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
Help with "MERGE" gratefully accepted
2 messages · Briggs, Meredith M, Andrew Stryker
Briggs, Meredith M <Meredith.Briggs at team.telstra.com> wrote on 2005-Apr-15:
Hello
Hi,
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
Your 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