[R] Subsetting rows by multiple levels of selected values
Ista Zahn
istazahn at gmail.com
Tue Aug 14 21:11:34 CEST 2012
Hi Jun,
I think
merge(df1, df2)
should do it.
Best,
Ista
On Tue, Aug 14, 2012 at 3:05 PM, Jun Shen <jun.shen.ut at gmail.com> wrote:
> 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