[R] Subsetting rows by multiple levels of selected values

arun smartpink111 at yahoo.com
Wed Aug 15 00:01:01 CEST 2012


HI,

In addition to merge(), you can also use: join()
library(plyr)
join(df1,df2,type="inner")

A.K.


----- Original Message -----
From: Jun Shen <jun.shen.ut at gmail.com>
To: R-help <r-help at stat.math.ethz.ch>
Cc: 
Sent: Tuesday, August 14, 2012 3:05 PM
Subject: [R] Subsetting rows by multiple levels of selected values

Dear list,

Let's say we have a data frame as follows,

>expand.grid(a=1:5,b=c(1,5,10,20),DV=c(0.1,0.2,0.3))->df1
>df1$DV<-rgamma(60,shape=10)

columns a and b are two levels. DV is the column with values we are
interested in.

Then another data frame df2 with values as follows

data.frame(a=c(2,2,3,4,5),b=c(5,10,1,5,20))->df2

Now I want to a subset of df1 that match df2 at the both columns a and b.
Any idea?

Thanks.

Jun

    [[alternative HTML version deleted]]

______________________________________________
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