Skip to content
Prev 309063 / 398503 Next

Merge matrices with different column names

Hello,

If you just want to write the matrices to a csv file instead of 
write.csv you can use write.table with options append=TRUE, sep="," and 
col.names=FALSE.

If you want to merge (rbind) them, you can use code similar to


pattern1 <- "(^var)[[:digit:]]+(.*$)"
pattern2 <- "(^var)_n_(.*$)"

colnames(Matrix1) <- sub(pattern1, "\\1_n_\\2", colnames(Matrix1))
colnames(Matrix2) <- sub(pattern1, "\\1_n_\\2", colnames(Matrix2))

Mat <- rbind(Matrix1, Matrix2)
colnames(Mat) <- sub(pattern2, "\\1_\\2", colnames(Mat))
Mat

Hope this helps,

Rui Barradas
Em 26-10-2012 04:51, Charles Determan Jr escreveu: