【发布时间】:2018-09-06 13:59:57
【问题描述】:
对于看起来像这样的数据框:
Value Id
1 xxx-rrr-ttt
78 ggg-oop-rty
97 fad-dar-oki
.. ..
.. ..
.. ..
我需要计算每一行的滚动平均值。因此对于数据框s,每行的滚动平均值将表示为s.mean。 R 中是否有可以计算 rolling-mean 的内置函数?我尝试了以下方法:
rollapply(data)
但它会引发错误argument "width" is missing, with no default。我无法理解这个错误以及width 的含义
【问题讨论】:
-
您可以使用来自
zoo的rollmean。使用rollapply,您需要传递函数和宽度参数。有疑问可以查看?rollapply的文档。width - numeric vector or list. In the simplest case this is an integer specifying the window width (in numbers of observations) which is aligned to the original sample according to the align argument. Alternatively, width can be a list regarded as offsets compared to the current time, see below for details. -
@akrun 我已经导入了包,但是不知道怎么用。
-
@akrun 你能举个例子作为答案吗?
-
您可能需要传递列名而不是完整的数据框。您的预期输出是什么?
-
@RonakShah 你是怎么把它称为重复的?任何与
moving mean相关的问题都不能重复。
标签: r