[R] Remove several numbers from a sequence

PIKAL Petr petr.pikal at precheza.cz
Mon Aug 20 16:32:42 CEST 2012


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of penguins
> Sent: Monday, August 20, 2012 1:15 PM
> To: r-help at 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 at 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.




More information about the R-help mailing list