是否可以重新排序数据帧的列,这是 dcast() 调用 Ex 的结果
给定数据:
> dput(copyOfRes)
structure(list(docName = c("doc2", "doc1", "doc1", "doc1", "doc1",
"doc1", "doc1", "doc1", "doc1", "doc1", "doc1", "doc2"), day_of_week = c(11,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 2)), .Names = c("docName",
"week_number"), row.names = c(NA, -12L), class = "data.frame")
因此,当我按如下方式使用 dcast() 时:
library(reshape2)
dcast(copyOfRes, docName ~ week_number, length)
结果是:
docName 2 11
1 doc1 0 10
2 doc2 1 1
我希望数据框的值减小week_number
如下:
docName 11 2
1 doc1 10 0
2 doc2 1 1
我试过做dcast(copyOfRes, docName ~ sort(week_number, decreasing= TRUE), length)
,但它仍然不起作用。有什么建议么?