R trailing cumsum per group
问题 I need to compute the running cumsum per group in R but the window over which to cumsum must only be the last 3 observations: If for example I have a table with a person's name, a date and a score as follow: Name Date Score 1 John 2017-01-01 4 2 John 2017-01-02 5 3 John 2017-01-03 3 4 John 2017-01-04 1 5 John 2017-01-05 4 6 John 2017-01-06 4 7 Ben 2017-01-01 4 8 Ben 2017-01-02 4 9 Ben 2017-01-03 5 10 Ben 2017-01-04 2 11 Ben 2017-01-05 3 12 Ben 2017-01-06 4 13 Ben 2017-01-07 4 14 Ben 2017-01