【发布时间】:2012-07-06 10:00:08
【问题描述】:
使用 reshape::cast 时,有没有办法设置结果列的名称?
例子:
library(reshape)
data(mtcars)
cast(mtcars, cyl + hp ~ .,mean)
cyl hp (all)
1 4 52 2
2 4 62 2
3 4 65 1
4 4 66 1
5 4 91 2
我希望能够在调用 cast 时设置名称,而不是 (all)。这可能吗?
我知道,我知道,好像输入colnames(x)[3] <- "Foo" 太难了,但如果你必须经常这样做,那就太费时间了!
【问题讨论】:
-
能否让您的示例可重现(包括加载必要的包等)?
-
你确定你从 reshape2 得到
cast吗?我以为那个函数被dcast替换了? -
reshape2被@chase(不是 OP)添加为编辑,我有一个修订版将其设置为reshape。reshape2将使用dcast并返回NA列名而不是(all) -
@mnel - 哦!对那里的混乱感到抱歉......我的帮助适得其反......我会回到我的洞穴。
-
最好的解决方案是向@hadley 发送功能请求:-p