【发布时间】:2014-08-30 06:00:54
【问题描述】:
我有成千上万个这样的数据集:
>student1
quantities score
[1] 4 10
[2] 1 12
[3] 78 5
[4] 6 294
我想计算这个学生的分数中位数。对于每个分数,我们都有一些数量。在这种情况下,我希望它返回 5,因为中位数是 78 个 5 之一。
我在这里查看了一些帖子,例如 how to calculate the median on grouped dataset? ,但我无法使用它,因为我有数千个数据集。
我也尝试安装aroma.light 包和matrixstats 包,但我仍然不能使用“weighted.median 函数”的东西。它告诉我
Error: could not find function "weightedMedians"
好的,上面只是一个例子,我的真实数据集是这样的:
>test
[,1] [,2]
info 3 10
info 2 20
4 86779637
1 135777
7 2342
但是当我尝试使用时
>rep(test[, 1], test[, 2])
它出现了
Error in rep(test[, 1], test[, 2]) : invalid 'times' argument
In addition: Warning message:
NAs introduced by coercion
我现在能做什么?
【问题讨论】: