小编kla*_*123的帖子

CumSum 基于组只计算一次值

我目前正在尝试创建一个累积总和列,它将根据 Game_ID 创建一个累积总和,但只计算与 Game_ID 相关的值一次。例如,玩家 A 在 Game_ID == 1 中进行了 20 次投篮,在 Game_ID == 2 中进行了 13 次投篮。对于累积总和,我希望 Shot_Count 值(基于 Game_ID)只计算一次,尽管出现在 Shot_Count 中列多次。考虑以下数据集:

Name         Game_ID       Shot_Count        CumSum_Shots
Player A         1             20                20 
Player B         1             15                15 
Player A         1             20                20
Player A         2             13                33 ## (20 + 13)
Player A         2             13                33 ## (20 + 13)
Player B         2             35                50 ## (15 + 35)
Player A         3             30                63 ## (33 + 30)
Player …
Run Code Online (Sandbox Code Playgroud)

r data-manipulation cumulative-sum data.table

2
推荐指数
1
解决办法
155
查看次数

标签 统计

cumulative-sum ×1

data-manipulation ×1

data.table ×1

r ×1