Re: [R] Matched pairs with two data frames

From: Udo <ukoenig_at_med.uni-marburg.de>
Date: Mon, 14 Apr 2008 08:37:51 +0200

Zitat von Peter Alspach <PAlspach_at_hortresearch.co.nz>:

> Udo
>
> Seems you might want merge()
>
> HTH .......
>
> Peter Alspach

Thank you Peter and Jorge,

but as I had written in my last sentence, "Merge doesn´t do the job, because it makes all possible matches", but maybe there is a sophisticated solution with "merge", I could not bring light to.

Udo

>
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org
> > [mailto:r-help-bounces_at_r-project.org] On Behalf Of Udo
> > Sent: Monday, 14 April 2008 6:41 a.m.
> > To: r-help_at_r-project.org
> > Subject: [R] Matched pairs with two data frames
> >
> > 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.
> >
>
> The contents of this e-mail are privileged and/or confidential to the named
> recipient and are not to be used by any other person and/or organisation.
> If you have received this e-mail in error, please notify the sender and
> delete
> all material pertaining to this e-mail.
>


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. Received on Mon 14 Apr 2008 - 06:45:07 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 Tue 15 Apr 2008 - 00: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