[R] Subsetting rows by multiple levels of selected values

Rui Barradas ruipbarradas at sapo.pt
Tue Aug 14 21:13:49 CEST 2012


Hello,

Try the following.

df3 <- merge(df2, df1)

Hope this helps,

Rui Barradas

Em 14-08-2012 20:05, Jun Shen escreveu:
> 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