且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从数据帧R中的0替换NA值

更新时间:2023-02-18 11:55:40

由于没有人觉得适合指出为什么你正在尝试什么不工作:

Since nobody so far felt fit to point out why what you're trying doesn't work:


  1. NA == NA 不返回 TRUE ,它返回 NA (因为与未定义的值相比应该会产生未定义的结果)。

  2. 您正试图在原子向量上调用 apply 。您不能使用 apply 来循环列中的元素。

  3. 您的下标关闭 - 您正在尝试将两个索引放入 a $ x 中,这只是列

  1. NA == NA doesn't return TRUE, it returns NA (since comparing to undefined values should yield an undefined result).
  2. You're trying to call apply on an atomic vector. You can't use apply to loop over the elements in a column.
  3. Your subscripts are off - you're trying to give two indices into a$x, which is just the column (an atomic vector).

我将修复3.获取 a $ x [is.na a $ x)]< - 0