开始使用 plyr `m*ply` 但无法重现示例
尝试学习 plyr,我在尝试从 介绍性指南< 中重现代码时遇到了困难/a>.
该指南说代码位于文件 plyr.r
中,但我在哪里可以找到该文件。
但复制第一个示例似乎很容易,所以我决定尝试一下:
dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
maply(dat, rnorm)
我明白了错误:
Error in function (..., na.last = TRUE, decreasing = FALSE) :
unimplemented type 'list' in 'orderVector1'
尝试
dat <- cbind(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
maply(dat, rnorm)
会提出
Error: Results must have the same dimensions.
问题:
- 我做错了什么?
- 在哪里可以找到 plyr.r? (它不是这里)
Trying to learn plyr, I have gotten stuck trying to reproduce code from the introductory guide.
The guide says that the code is in a file plyr.r
, but not where I can find this file.
But reproducing one of the first examples seemed easy enough, so I decided to give it a try:
dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
maply(dat, rnorm)
and I get this error:
Error in function (..., na.last = TRUE, decreasing = FALSE) :
unimplemented type 'list' in 'orderVector1'
trying
dat <- cbind(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
maply(dat, rnorm)
gives
Error: Results must have the same dimensions.
questions:
- what am I doing wrong?
- where can I find plyr.r? (it is not here)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:
并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。
正如您在文档 (
?mdply
) 中看到的,以下示例非常有用:如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用
mlply
,例如:The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:
And the m*pply function do not know what to do with the 'c.10..100..50...' column.
As you can see in the docs (
?mdply
), the following example works like a charm:If you really want different number of observations with the different parameters, you should not use mdply, because the matrix/data.frame must have the same number of columns. Insted use
mlply
, e.g.: