I only collect the great offers that others have already given. I like the ability to store this as a function and generalize values except 1, including categorical values (also selects positively or negatively with the select argument):
v.omit <- function(dataframe, v = 0, select = "neg") { switch(select, neg = dataframe[apply(dataframe, 1, function(y) !any(y %in% (v))), ], pos = dataframe[apply(dataframe, 1, function(y) any(y %in% (v))), ]) }
Give it a try.
x <- matrix(c(0,0,0,1,1,0,1,1,1,1,NA,1), ncol = 2, byrow = TRUE) v.omit(x) v.omit(mtcars, 0) v.omit(mtcars, 1) v.omit(CO2, "chilled") v.omit(mtcars, c(4,3)) v.omit(CO2, c('Quebec', 'chilled')) v.omit(x, select="pos") v.omit(CO2, c('Quebec', 'chilled'), select="pos") v.omit(x, NA) v.omit(x, c(0, NA))
Please do not mark my answer as correct, as others answered in front of me, this is just to expand the conversation. Thanks for the code and the question.