Convert from n x m matrix to long matrix in R

北战南征 提交于 2019-11-29 13:32:21

If you need a single column matrix

 matrix(m, dimnames=list(t(outer(colnames(m), rownames(m), FUN=paste)), NULL))
 #    [,1]
 #a d    1
 #a e    4
 #b d    2
 #b e    5
 #c d    3
 #c e    6

For a data.frame output, you can use melt from reshape2

 library(reshape2)
 melt(m)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!