one way is the following: X <- matrix(c(10,20,30,40,50,60), 2, 3, dimnames = list(c("1","2"), c("1","2","3")))
tX <- t(X) cbind( rows = c(col(tX)), columns = c(row(tX)), entries = c(tX) ) I hope it helps. Best, Dimitris Dimitri Liakhovitski wrote:
Hello, I have a matrix that is a product of tapply on a larger data set. Let's assume it looks like this: X<-matrix(c(10,20,30,40,50,60),2,3) dimnames(X)<-list(c("1","2"),c("1","2","3")) (X) 1 2 3 1 10 30 50 2 20 40 60 Is there an efficient way of transforming this matrix into the following matrix: rows columns entries 1 1 10 1 2 30 1 3 50 2 1 20 2 2 40 2 3 60 Thank you very much!
-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.