开始使用 plyr `m*ply` 但无法重现示例

发布于 2024-10-10 08:50:21 字数 892 浏览 3 评论 0原文

尝试学习 plyr,我在尝试从 介绍性指南< 中重现代码时遇到了困难/a>.

该指南说代码位于文件 plyr.r 中,但我在哪里可以找到该文件。

但复制第一个示例似乎很容易,所以我决定尝试一下:

alt text

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.

问题:

  1. 我做错了什么?
  2. 在哪里可以找到 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:

alt text

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:

  1. what am I doing wrong?
  2. where can I find plyr.r? (it is not here)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨光如昨 2024-10-17 08:50:21

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

> mlply(data.frame(n=1:5, mean = 1:5, sd = 1:5), rnorm)

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

1` [1] 1.053083

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

2` [1] -1.650090 2.239547

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

3` [1] -0.94697908 -1.11479730 -0.03467497

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

4` [1] 6.427796 1.482655 1.436822 -5.993420

您制作的数据框具有与 rnorm 函数不兼容的标头 (col.names)。请参阅:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

并且 m*pply 函数不知道如何处理 'c.10..100..50...' 列。

正如您在文档 (?mdply) 中看到的,以下示例非常有用:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

如果您确实想要使用不同参数进行不同数量的观察,则不应使用 mdply,因为矩阵/ data.frame 必须具有相同的列数。安装使用 mlply,例如:

5` [1] 4.557689 6.217015 2.105255 -1.309664 -2.969184 attr(,"split_type") [1] "array" attr(,"split_labels") n mean sd 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

> mlply(data.frame(n=1:5, mean = 1:5, sd = 1:5), rnorm)

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

1` [1] 1.053083

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

2` [1] -1.650090 2.239547

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

3` [1] -0.94697908 -1.11479730 -0.03467497

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

4` [1] 6.427796 1.482655 1.436822 -5.993420

The data frame you made has a header (col.names) which is not compatible with the rnorm function. See:

> dat <- data.frame(c(10,100,50), mean=c(5,5,10), sd=c(1,2,1))
> dat
  c.10..100..50. mean sd
1             10    5  1
2            100    5  2
3             50   10  1

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:

> mdply(data.frame(mean = 1:5, sd = 1:5), rnorm, n = 2)
  mean sd         V1         V2
1    1  1 0.09919179  0.6083586
2    2  2 0.92787891 -0.1139743
3    3  3 2.21236781  0.8029677
4    4  4 4.16506428  9.2477373
5    5  5 1.26558507 12.0633377

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.:

5` [1] 4.557689 6.217015 2.105255 -1.309664 -2.969184 attr(,"split_type") [1] "array" attr(,"split_labels") n mean sd 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文