dataframe subset

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

dataframe subset

Bernhard Baumgartner
Thanks to all,

the %in% function solved my problem!

Bernhard

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: dataframe subset

bogdan romocea
Here's one way,
  x <- data.frame(V=c(1,1,1,1,2,2,4,4,4,9,10,10,10,10,10))
  y <- data.frame(V=c(2,9,10))
  xy <- merge(x,y,all=FALSE)
Pay close attention to what happens if you have duplicate values in y, say
  y <- data.frame(V=c(2,9,10,10))


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Bernhard Baumgartner
> Sent: Wednesday, February 08, 2006 9:22 AM
> To: [hidden email]
> Subject: [R] dataframe subset
>
> I have a dataframe with a column, say "x" consisting of values, each
> value appearing different times, e.g.
> x: 1,1,1,1,2,2,4,4,4,9,10,10,10,10,10 ...
> and a vector, including e.g.:
> y: 2,9,10,...
> I need a subset of the dataframe: all rows where x is equal to one of
> the values in y. Currently I use a loop for this, but because x and y
> are large this is very slow.
> Is there any idea how to solve this problem faster?
> Thank you,
> Bernhard
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html