If I have a dataframe and I want to use rolling sum to sum the previous n rows and the next n rows, what is the best way to do this? I'm aware of the roll_sum, but I can't find a way to use it to fit my use case. For example let's say I have the a vector n. And I specify that I want my window to be 1, that means for each record I want to sum it and the two adjacent records.
n window1
1 NA
3 8
4 12
5 15
6 18
7 22
9 17
1 15
5 6
If I specified 2 as my window size then this would be the result:
n window1 window2
1 NA NA
3 8 NA
4 12 19
5 15 25
6 18 31
7 22 28
9 17 28
1 15 22
5 6 15
Is there an easy way to do this?