Hello How do I use function 'MERGE" to combine the FILE A and FILE B below to make FILE C? Thank you FILE A 140 151 167 30.1 11.4 40 FILE B 140 167 5.7 30.3 FILE C 140 151 167 30.1 11.4 40 5.7 NA 30.3
> dat1 <- data.frame(var1=c(140, 151, 167), var2=c(30.1, 11.4, 40)) > dat2 <- data.frame(var1=c(140, 167), var3=c(5.7, 30.3)) > merge(dat1, dat2, all=TRUE)var1 var2 var3 1 140 30.1 5.7 2 151 11.4 NA 3 167 40.0 30.3 Matt Austin Statistician Amgen One Amgen Center Drive M/S 24-2-C Thousand Oaks CA 93021 (805) 447 - 7431 "Today has the fatigue of a Friday and the desperation of a Monday" -- S. Pearce 2005 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Briggs, Meredith M Sent: Thursday, April 14, 2005 18:26 PM To: r-help at stat.math.ethz.ch Subject: [R] Help with "MERGE" gratefully accepted Hello How do I use function 'MERGE" to combine the FILE A and FILE B below to make FILE C? Thank you FILE A 140 151 167 30.1 11.4 40 FILE B 140 167 5.7 30.3 FILE C 140 151 167 30.1 11.4 40 5.7 NA 30.3 ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Briggs, Meredith M <Meredith.Briggs at team.telstra.com> wrote on 2005-Apr-15:> > HelloHi,> How do I use function 'MERGE" to combine the FILE A and FILE B below to make FILE C? > > Thank you > > > > FILE A > 140 151 167 > 30.1 11.4 40 > > FILE B > > 140 167 > 5.7 30.3 > > FILE C > > 140 151 167 > 30.1 11.4 40 > 5.7 NA 30.3Your problem is much easier to solve if the data are arranged differently. Say, File A ID, VAR_A 140, 30.1 151, 11.4 167, 40 File B ID, VAR_B 140, 5.7 167, 30.3 File C ID, VAR_C, VAR_D 140, 30.1, 5.7 151, 11.4, NA 167, 40, 30.3 Those files can be read with read.csv into data frames. A simple ab <- merge(fa, fb) where fa is the data frame for file A and fb the same for file B will put you have the way there. Pay attention to the all.x and all.y options. I suspect there is a way to do the transposition in R. However, indexing records as rows and fields as columns is the standard approach. If you follow this convention, you will find that many tools, not just R, are much more likely to work with you. Good luck, Andrew