Re: [R] dataframe subset

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Thu 09 Feb 2006 - 02:07:38 EST


Hi

something like

xx<-data.frame(x=sample(1:10,100,replace=T)) y<-c(2,5,8)
xx[xx$x%in%y,]

HTH
Petr

On 8 Feb 2006 at 15:21, Bernhard Baumgartner wrote:

From:           	"Bernhard Baumgartner" <bernhard.baumgartner@wiwi.uni-regensburg.de>
Organization:   	Universitaet Regensburg
To:             	r-help@stat.math.ethz.ch
Date sent:      	Wed, 08 Feb 2006 15:21:46 +0100
Priority:       	normal
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
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 09 02:42:45 2006

This archive was generated by hypermail 2.1.8 : Fri 10 Feb 2006 - 21:35:24 EST