I've got
a <- matrix(c(1,3,4,2,2,6,3,1,6), nrow = 3, ncol=3, byrow=TRUE, dimnames = list(NULL, c("Apples", "Pears", "Oranges")))
Pears Apples Oranges
1 1 3 4
2 2 2 6
3 3 1 6
b <- matrix(c(1,3,2,6,3,6), nrow = 3, ncol=2, byrow=TRUE, dimnames = list(NULL, c( "Pears", "Oranges")))
Pears Oranges
1 1 4
2 2 6
3 3 6
I want to merge them to get a result as such:
Pears Apples Oranges
1 1 3 4
2 2 2 6
3 3 1 6
4 1 Na 4
5 2 Na 6
6 3 Na 6
Ie, combine them by column name an leave Na/s where the second frame lacks values, for a general case of bigger matrix a, smaller matrix b
rbind does not work, merge does something weird. What am I after? I could do with the most memory efficient thing available too, as this is eventually going to be done a large number of times, with a lot of column names.
Thanks,
-N
EDIT: I probably should have mentioned this when I asked originally, but I actually want to achieve the exact effect as above, but with some pretty major caveats:
I'm using matrices
The first matrix will always contain all and more colnames than the second
I possibly want to create a big.matrix from package bigmemory.