[R] How to Merge based on Rows
MRKidd
clistkoraelus at yahoo.com
Fri Jan 8 22:21:33 CET 2010
Let's say that I have a bunch of matrices.
They look like this (pardon using fruit for examples, my actual data tables
are far too enormous):
Matrix1
Apples Oranges Pears
A 5 6 7
B 5 3 4
C 8 9 10
D 11 13 14
E 15 3 8
F 1 4 5
Matrix2
Apples Oranges Pears
A 5 3 9
B 3 2 1
C 3 4 5
E 8 1 4
G 3 2 1
I cannot use cbind or rbind, because I have different rows in each matrix
(e.g. - F & D are missing for Matrix2 and G is missing from Matrix1).
What I would like to have in the end is this
Apples Oranges Pears Apples Oranges Pears
A 5 6 7 5 3 9
B 5 3 4 3 2 1
C 8 9 10 3 4 5
D 11 13 14 NA NA NA
E 15 3 8 8 1 4
F 1 4 5 NA NA NA
G NA NA NA 3 2 1
I have experimented with the merge() cmd, but my trial and error efforts
have failed miserably. If anyone knows of a way to combine these matrices
other than manually editing them together, please let me know.
p.s.
The way I have organized the matrices is such that they all have the same
column names. So Matrix 1 and Matrix 2 will have the exact same column names
- but I want the newly combined matrix to keep the columns separate. So, as
in my final example, there would be one column titled "Apples" for each
Matrix that I add in.
--
View this message in context: http://n4.nabble.com/How-to-Merge-based-on-Rows-tp1010000p1010000.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list