Hi Lazarus, It would be more simple with mdat as a matrix (before coercing to a data.frame). It might be a simpler way to compare a matrix with a vector but I don't find it for the moment; in any case, this works: mdatT <- matrix(mdat %in% c(1, 11, 20), ncol=3) > mdat[!apply(mdatT, 1, any), ] C.1 C.2 C.3 row2 4 5 6 row3 7 8 9 row5 13 14 15 row6 16 17 18 Or you can use apply directly on a data.frame, with the same result: mdat <- as.data.frame(mdat) > mdat[!apply(mdat, 1, function(x) any(x %in% c(1, 11, 20))), ] C.1 C.2 C.3 row2 4 5 6 row3 7 8 9 row5 13 14 15 row6 16 17 18
hth, Adrian On Thursday 05 March 2009, Lazarus Mramba wrote: > Dear R-help team, > > I am getting addicted to using R but keep on getting many challenges on the > way especially on data management (data cleaning). > > I have been wanting to drop all the rows if there values are `NA' or have > specific values like 1 or 2 or 3. > > > mdat <- matrix(1:21, nrow = 7, ncol=3, byrow=TRUE, > dimnames = list(c("row1", > "row2","row3","row4","row5","row6","row7"), c("C.1", "C.2", "C.3"))) > mdat<-data.frame(mdat) > mdat > > C.1 C.2 C.3 > row1 1 2 3 > row2 4 5 6 > row3 7 8 9 > row4 10 11 12 > row5 13 14 15 > row6 16 17 18 > row7 19 20 21 > > I want to say drop row if value=1 or value =11 or value =20 > > How do I do that? > > > Kind regards, > Lazarus Mramba -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[alternative HTML version deleted]] ______________________________________________ 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.