R matrix to rownames colnames values

You could use the reshape2-package:

# load package
> require(reshape2)
# create an example matrix
> mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE,
+                dimnames = list(c("row1", "row2"),
+                                c("C.1", "C.2", "C.3")))
> mdat
     C.1 C.2 C.3
row1   1   2   3
row2  11  12  13
# bring matrix to long format using melt()
> melt(mdat)
  Var1 Var2 value
1 row1  C.1     1
2 row2  C.1    11
3 row1  C.2     2
4 row2  C.2    12
5 row1  C.3     3
6 row2  C.3    13

Leave a Comment