Hi > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of penguins > Sent: Monday, August 20, 2012 1:15 PM > To: r-help@r-project.org > Subject: Re: [R] Remove several numbers from a sequence > > Hi! > > Both yy[!(yy %in% xx)] and yy[is.na(match(yy,xx))] work a treat! > > Developing this topic can anyone tell me how to extract rows which are > not replicated across 2 data frames. For example: > > z1<-c(1,2,3,4) > z2<-c(5,6,7,8) > zz<- data.frame(cbind(z1,z2)) > > x1<-c(3,4) > x2<-c(7,8) > xx<- data.frame(cbind(x1,x2)) > > so the result would be: > > 1 5 > 2 6 > > Using setdiff(xx,zz) I can get the replicated rows but not the unique > ones, and setdiff(zz,xx) returns the all rows.
I am not sure how setdiff works with data.frames }nothing is said in help page so you need to go to source. sapply((zz), function(x) x %in% t(xx)) gives you data frame with true values but I am not sure if it works only for this example or globally. After that just check number of true values and select appropriate rows. Regards Petr > > Many thanks > > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Remove- > several-numbers-from-a-sequence-tp4640630p4640771.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. ______________________________________________ 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.