Re: [R] Matched pairs with two data frames

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Sun, 13 Apr 2008 17:58:25 -0400

Hi Udo,

Perhaps

> merge(treat,control)

does what you need.

I hope this helps,

Jorge

On Sun, Apr 13, 2008 at 2:41 PM, Udo <ukoenig_at_med.uni-marburg.de> wrote:

> Hi,
> I have a frame "treat" and want to find matched pairs in the data frame
> "control". In the matched (combined) data frame there should be two
> variables (0/1),indicating the "source" of the data (treat or control),
> so that it is possibe to set a "filter" (extraxt/select data).
>
> #Here are the dataframes (my real data frames have many variables)
> treat <- data.frame(age=c(1,1,2,2,2,4),
> school=c(10,10,20,20,20,11),
> out1=c(9.5,2.3,3.3,4.1,5.9,4.6))
> control <- data.frame(age=c(1,1,1,1,3,2),
> school=c(10,10,10,10,33,20),
> out2=c(1.1,2,3.5,4.9,5.2,6.5))
> print(treat)
> print(control)
>
> matched.data.frame <- ?????? #Match "treat" "control" by age school
>
>
> #My SPSS syntax would be similar to this:
> MATCH FILES FILE="treat" /IN=fromtreat
> /FILE="control" /IN=fromcontrol
> /BY age school.
> SELECT IF fromdad AND fromfam. #select data, set filter
>
> The /IN= option creates a 0/1 variable that indicates the
> "source" of the data
>
> The resultand matched data frame should have
> the following structure:
> age school out1 out2 fromtreat fromcontrol
> 1 10 9.5 1.1 1 1
> 1 10 2.3 2.0 1 1
> ....
> 4 11 4.6 NA 1 0
> 3 33 NA 5.2 0 1
> ....
>
> I tried "which" and "match", but I failed and was unlucky looking
> at the help/archive. Merge doesn´t do the job, because it makes
> all possible matches.
>
>
> Thank´s for any help!
> Udo
>
>
> --------------------------------------------
> Udo K N G
> Ö I
>
> Clinic for Child an Adolescent Psychiatry
> Philipps University of Marburg / Germany
>
> ______________________________________________
> 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.

        [[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. Received on Sun 13 Apr 2008 - 22:11:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Apr 2008 - 23:30:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive