小编dia*_*iii的帖子

R:传递多个参数来累加/减少

这与R有关:使用上一行新生成的数据

我意识到我面临的实际问题比我在上面线程中给出的示例要复杂一些 - 似乎我必须将 3 个参数传递给递归计算才能实现我想要的。因此,accumulate2reduce可能不起作用。所以我在这里提出一个新问题以避免可能的混淆。

我有以下按 ID 分组的数据集:

ID <- c(1, 2, 2, 3, 3, 3)
pw <- c(1:6)
add <- c(1, 2, 3, 5, 7, 8)
x <- c(1, 2, NA, 4, NA, NA)
df <- data.frame(ID, pw, add, x)

df
  ID pw add  x
1  1  1   1  1
2  2  2   2  2
3  2  3   3 NA
4  3  4   5  4
5  3  5   7 NA
6 …
Run Code Online (Sandbox Code Playgroud)

iteration r accumulate rolling-computation

5
推荐指数
2
解决办法
222
查看次数

标签 统计

accumulate ×1

iteration ×1

r ×1

rolling-computation ×1