[R] matching pairs in a Dataframe?

Stefan Grosse singularitaet at gmx.net
Wed Aug 16 19:50:45 CEST 2006


I found a solution:

pairs<-merge(subset(data.frame,cond==2,select=c(group,x),subset(data.frame,cond==3,select=c(group,x)),by=c("group"))

That yields something like

group   cond.x   cond.y
A      4      6.5
D      5      6
E      4      6


now I just need to figure out how I embed this into a function together
with the test, so that I don't have to write to much ....

Stefan Grosse

> Dear list,
>
> I want to extract pairs of values out of a dataframe where one
> criteria/condition does match.
>
> I have an experiment with 3 conditions which were not always applied:
>
> e.g.:
>
> group   cond   x
> A         1         2
> A         2         4
> A         3         6.5
> B         1         3
> B         2         4.5
> C         1         2.5
> C         3         4
> D         2         5
> D         3         6
> E         1         1
> E         2         4
> E         3         6
>
>
> Now I wanted to extract the x of those groups where condition 2 and
> condition 3 do both exist.
>
> In this example that would be groups A, D and E and the extracted pairs
> e.g.:
> cond2   cond3
> 4         6.5
> 5         6
> 4         6
>
>



More information about the R-help mailing list