I have a simple vector as follows:
x = c(14.24, 13.82, 12.75, 12.92, 12.94, 13.00, 14.14, 16.28, 20.64, 17.64)
I am trying to find the rolling mean of this vector and using the following function:
library(data.table)
y = frollmean(x, 5)
I am getting the result as follows -
[1] NA NA NA NA 13.334 13.086 13.150 13.856 15.400 16.340
However, I want the result as -
[1] 14.24 14.03 13.06 13.43 13.334 13.086 13.150 13.856 15.400 16.340
- The first value should be the same as in the original vector
- The second value should be the mean of the first and second value
- The third value should be the mean of the initial three values in the vector
- The fourth value should be the mean of the initial four values in the vector
The rest of the calculation is correctly handled by the function frollmean
Any suggestions will be helpful.
Thanks!