I have a dataframe as this
> df<-data.frame(index=c(1,2,3,4,5,6),value=c(2,3,5,8,11,12))
> df
index value
1 1 2
2 2 3
3 3 5
4 4 8
5 5 11
6 6 12
I want to create a new column which equals to the the sum of three adjacent values of column value indexed by column index, that is
> df_res
index value res
1 1 2 NA
2 2 3 10
3 3 5 16
4 4 8 24
5 5 11 31
6 6 12 NA
The second row of res is the sum of (2,3,5), third sum(3,5,8) etc. (the first and last row of res do not matter, and I temporarily set it as NA)
How can I get it done in R?