2014-07-17 152 views

回答

1

你所寻找的是meltlibrary(reshape)

melt(matrix) 

编辑:改为使用reshape2

+2

重塑很好用 – user3083324

+0

好点,最好使用'reshape2.''reshape :: melt()'和'reshape2 :: melt()'似乎在功能上是一致的。 – Vlo

2

看看rowcol,并为R基本解决c功能和尝试这样的事情

df <- data.frame(row=c(row(matrix)), col=c(col(matrix)), value=c(matrix)) 
+0

尼斯data.frame。我会提及[这个问题](http://stackoverflow.com/questions/11176781/r-matrix-to-rownames-colnames-values/11176964),它具有用rownames/colnames/value生成data.frame的示例。 – thelatemail

0

另一个想法:

data.frame(cbind(arrayInd(seq_along(matrix), dim(matrix), useNames = T), 
       value = c(matrix))) 

或者:

tmp = as.data.frame.table(matrix) 
tmp[-length(tmp)] = sapply(tmp[-length(tmp)], as.integer) 
相关问题