是否“总结”? plyr中的功能还存在吗?
使用 plyr 时,我经常想要 1) 仅对变量的子集执行操作,2) 命名操作的输出。例如:
d = data.frame(sex=c("m","f","m","m","f","f"), age=c(30,20,15,50,10,40), weight=c(130,120,115,150,90,180))
ddply(d, .(sex), function(df) data.frame(age_mu = mean(df$age)))
但这看起来有点笨拙,而且我似乎应该能够写出类似的东西:
ddply(d, .(sex), age_mu = mean(age))
从我读到的内容来看,看起来有(或曾经有?) plyr 中包含一个汇总函数,这将请允许我写:
ddply(d, .(sex), transform, age_mu = mean(age))
但是,当我尝试使用汇总函数时,R 告诉我它不存在。它是否被重命名或移动到另一个包中?我在 Mac 上使用 plyr 版本 0.1.5(我相信这是最新的——我尝试更新)。
When using plyr, I often want to 1) perform an operation on only a subset of the variables and 2) name the output of the operation. For example:
d = data.frame(sex=c("m","f","m","m","f","f"), age=c(30,20,15,50,10,40), weight=c(130,120,115,150,90,180))
ddply(d, .(sex), function(df) data.frame(age_mu = mean(df$age)))
But this seems kinda clunky, and it seems like I should be able to write something like:
ddply(d, .(sex), age_mu = mean(age))
From what I've read, it looks like there is (or used to be?) a summarise function included in plyr, that would allow me to write:
ddply(d, .(sex), transform, age_mu = mean(age))
However, when I try to use the summarise function, R tells me it doesn't exist. Has it been renamed or moved into another package? I'm using plyr version 0.1.5 (which I believe is the latest -- I tried updating) on a Mac.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,它仍然存在。我使用的是 plyr 版本 1.1,所以你的版本似乎很旧。
Yes, it still exists there. I'm using plyr version 1.1 so your version seems to be very old.