Dear all,

I have two species-by-site matrices and I'd like to combine them in one
matrix. The rows (n=20) of each matrix present plants 1-20. So, the new
matrix should have 40 rows. As these matrices have some shared species and
some exclusive species, the new matrix should have the species from the two
matrix, but when certain species that doesn't occur for example in Matrix
1, its value will be 0. I've tried the functions merge, cbind and rbind but
I wasn't able to do it. Please, see the following example to make it clear
;-)


By using for example the following matrices:

matrix1 <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE,
               dimnames = list(c("plant1", "plant2"),
                               c("sp1", "sp2", "sp3")))

matrix2 <- matrix(c(1,2,3, 0,21,9), nrow = 2, ncol=3, byrow=TRUE,
               dimnames = list(c("plant3", "plant4"),
                               c("sp1", "sp2", "sp4")))

I'd like to combine them  like this:

new.matrix <- matrix(c(1, 2, 3, 0, 11, 12, 13, 0, 1, 2, 0, 3, 0,21,0,9),
              nrow = 4, ncol=4, byrow=TRUE,
               dimnames = list(c("plant1", "plant2", "plant3", "plant4"),
                               c("sp1", "sp2", "sp3", "sp4")))

Once I have 200 columns and 80 rows, I'm pretty sure that R can help me to
do it automatically ;-)


All the best,
Thiago.


-- 
Thiago Gonçalves-Souza, Ms.
Universidade Estadual Paulista (UNESP)
Departamento de Zoologia e Botânica
Programa de Pós-Graduação em Biologia Animal (Doutorado)
E-mail alternativo: thiagoaracno@gmail.com
Home page:<http://www.wix.com/thiagocalvesouza/tg-s>

	[[alternative HTML version deleted]]

