[R] R: dataframe subset

Guazzetti Stefano Stefano.Guazzetti at ausl.re.it
Wed Feb 8 15:52:42 CET 2006


Dear Bernhard,
if I understand correctly your question
may be you want something like

 df<-data.frame(x=sample(1:10, 100, repl=T), 
                y=sample(1:5, 100, repl=T))
 subset(df, x%in%y)

Regards, 

Stefano

   >-----Messaggio originale-----
   >Da: r-help-bounces at stat.math.ethz.ch
   >[mailto:r-help-bounces at stat.math.ethz.ch]Per conto di Bernhard
   >Baumgartner
   >Inviato: 08 February 2006 15:22
   >A: r-help at stat.math.ethz.ch
   >Oggetto: [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 at 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




More information about the R-help mailing list