views:

131

answers:

1

Hello, I would like to create a new dataset where the following four conditions are all met.

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

Thanks!

+8  A: 

Then use the & operator:

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, ]

A single & is a vectorized function, while a double && is unary (typically used in an if statement, for instance).

Shane