If the data is a dataframe or matrix 'd':

d <- d[apply(d, 1, function(v) sum( is.na(v) ) <= 2 & sum(v==0, na.rm=T) <=
2 ), ]

which can be deconstructed as follows:

i1 <- apply(d, 1, function(v) sum(is.na(v)) <= 2 ) ## true for rows with 2
or fewer na's
i2 <- apply(d, 1, function(v) sum( v == 0, na.rm=T ) <= 2 ##true for rows
with 2 or fewer 0's

i1 & i2 ##logical vector, true for rows satisfying both conditions

d[ i1 & i2, ] ##only those rows satisfying the condition, and all columns


-- 
View this message in context: 
http://n4.nabble.com/help-deleting-rows-which-contain-more-than-2-NAs-or-zeros-tp1584613p1584641.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to