So I have a list of a 17 matrices that I want to combine into a single master matrix. However, I also want different values for an observation to be appended instead of being overwritten. For a simplified example,
m1 <- matrix( c(1, 0, 0, 0, 1, 0, 0, 0, 1), nrow=3, ncol=3)
rownames(m1) <- c("x", "y", "z")
colnames(m1) <- c("a", "b", "c")
m2 <- matrix( c(2, 0, 0, 0, 2, 0, 0, 0, 2), nrow=3, ncol=3)
rownames(m2) <- c("a", "d", "e")
colnames(m2) <- c("x", "w", "z")
m3_final <- matrix( c(0, 0, 0, 2, 0, "1;2", 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 2), nrow=5, ncol=4)
rownames(m3_final) <- c("a", "b", "c", "d", "e")
colnames(m3_final) <- c("w", "x", "y", "z")
My current thoughts are to run a for loop through the list so that each matrix is iterated into an empty master matrix to begin with, but I am having trouble with appending a new result to a previous result. My current error:
m1 <- matrix( c(1, 0, 0, 0, 1, 0, 0, 0, 1), nrow=3, ncol=3)
rownames(m1) <- c("x", "y", "z")
colnames(m1) <- c("a", "b", "c")
m2 <- matrix( c(2, 0, 0, 0, 2, 0, 0, 0, 2), nrow=3, ncol=3)
rownames(m2) <- c("a", "d", "e")
colnames(m2) <- c("x", "w", "z")
m3_final <- matrix( c(0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 2), nrow=5, ncol=4)
rownames(m3_final) <- c("a", "b", "c", "d", "e")
colnames(m3_final) <- c("w", "x", "y", "z")
Thanks for any help!