I am trying to calculate the rolling sum of the values in column ‘a’ for n leading values as specified in column b so that i get the answer as specified in column c
I tried to use slide_sum but when i pass the value of the argument ‘after’ as the column b, it throws an error.
d %>% mutate(c = slide_sum(a, after = b))
Error:
Error in `mutate()`:
ℹ In argument: `c = slide_sum(a, after = b)`.
Caused by error:
! `after` must have size 1, not 10.
Run `rlang::last_trace()` to see where the error occurred.