Re: [R] About matrix manipulation

2012-08-21 Thread Rui Barradas
Hello, Try the following. library(reshape2) # Don't need 'cbind' mat <- data.frame(sp1=c(rep(0, 5), rep(1, 5)), sp2=sample(c(rep(0, 6),rep(1, 4))), fac=c(rep("a", 3), rep("b", 3), rep("c", 4))) mat.new <- matrix (c(0, 1, 1, 1, 1, 1), nrow=2, ncol=3) rownames(mat.new) <- c("sp1

[R] About matrix manipulation

2012-08-21 Thread Thiago Gonçalves-Souza
Dear list, I'm trying to create a matrix by combining the sites that species occur in a new matrix with species as rows and sites as columns. The main matrix is "mat": mat <- as.data.frame(cbind(sp1=c(rep(0, 5), rep(1, 5)),sp2=sample(c(rep(0, 6),rep(1, 4))), fac=c(rep("a", 3), rep("b", 3),rep("c