【发布时间】:2015-11-05 12:12:20
【问题描述】:
如何将我的数据框“水果”转换为矩阵
> fruits
Month Apple Mango Banana
1 June 149579 36051 28124
2 July 198742 37228 30354
3 August 397145 36483 31140
4 September 329559 37101 31588
5 October 144107 35917 29444
6 November 19432 8587 5382
7 December 0 0 0
我想把月份和水果的名字作为矩阵的头
【问题讨论】:
-
你能显示预期的输出吗?你需要
library(reshape2);acast(melt(fruits, id.var='Month'), variable~Month, value.var='value')还是as.matrix('row.names<-'(fruits[-1], fruits[,1])) -
你是救世主。谢谢你。我正在寻找第二个答案。