报告R中多行的特定列的单元格内容

报告R中多行的特定列的单元格内容,r,R,我需要让R输出数据帧(称为“rats.df”)中包含缺失值的行的“sample ID”。到目前为止,我已经能够获得包含缺失值的数据帧的行号: missing.val <- unique( unlist( lapply (rats.df, function (x) which (is.na (x))))) sort (missing.val, decreasing=FALSE) 我在另一个页面上找到了这段代码,但因为我不完全理解它,所以无法将其应用于我的数据帧

我需要让R输出数据帧(称为“rats.df”)中包含缺失值的行的“sample ID”。到目前为止,我已经能够获得包含缺失值的数据帧的行号:

missing.val <- unique( unlist( lapply (rats.df, function (x) 
              which (is.na (x)))))
sort (missing.val, decreasing=FALSE)
我在另一个页面上找到了这段代码,但因为我不完全理解它,所以无法将其应用于我的数据帧。好吧,我试过了,但不知怎么的,它没有给我想要的输出:

index <- which(rats.df==113, arr.ind=TRUE)
paste(rownames(rats.df)[index[1]], colnames(rats.df)[index[1]], sep=", ")
index您只需要

rats.df[!complete.cases(rats.df), "sampleId"]

完成。对于没有丢失数据的行,cases
将返回TRUE。因此,对该向量求反将得到缺失数据行的索引。

非常感谢!似乎很简单,但因为我是初学者,我没有想到否定这个论点。
rats.df[!complete.cases(rats.df), "sampleId"]