[R] transposing a matrix - row by row?

Dimitri Liakhovitski ld7631 at gmail.com
Thu Apr 23 16:31:16 CEST 2009


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!
-- 
Dimitri Liakhovitski
MarketTools, Inc.
Dimitri.Liakhovitski at markettools.com



More information about the R-help mailing list