R问题。创建满足所有4个条件的新数据集

时间:2010-05-16 17:15:35

标签: r statistics conditional dataframe

我想创建一个新的数据集,其中满足以下四个条件。

rowSums(is.na(UNCA[,11:23]))<12

rowSums(is.na(UNCA[,27:39]))<12

rowSums(is.na(UNCA[,40:52]))<12

rowSums(is.na(UNCA[,53:65]))<12

谢谢!

1 个答案:

答案 0 :(得分:9)

然后使用&运算符:

UNCA.new <- UNCA[rowSums(is.na(UNCA[,11:23])) < 12 & 
                 rowSums(is.na(UNCA[,27:39])) < 12 & 
                 rowSums(is.na(UNCA[,40:52])) < 12 &  
                 rowSums(is.na(UNCA[,53:65])) < 12, ]

单个&是向量化函数,而双&&是一元(例如,通常在if语句中使用)。