Zitat von Peter Alspach <[EMAIL PROTECTED]>: > 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: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Udo > > Sent: Monday, 14 April 2008 6:41 a.m. > > To: r-help@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@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@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.