Say I have two matrices:
M1 <- matrix(letters[1:9], nrow = 3, ncol = 3, byrow = T)
M2 <- matrix(letters[10:18], nrow = 3, ncol = 3, byrow = T)
In reality I have much larger matrices with 1000 rows. What I'd like is an efficient way to produce the following without using for loops as this causes R to crash.
result <- rbind(cbind(M1, matrix(rep(letters[10:12], 3), nrow = 3, ncol = 3, byrow = T)),
cbind(M1, matrix(rep(letters[13:15], 3), nrow = 3, ncol = 3, byrow = T)),
cbind(M1, matrix(rep(letters[16:18], 3), nrow = 3, ncol = 3, byrow = T)))
Essentially "paste" every row of M2 onto every row of M1 so that I have every possible combination.