I have a long time series of a variable. I want to perform a backward moving average with window size of 20. If I keep this window size then the output series will be shortened by length 20 (I mean first 20 values will be NAs) but what I want is that the the output series should be of same length as original series with non NAs. For this, I want to vary the window size in the beginning so that I can get the desired output. For example, for the first 20 values in original time series, the moving window size can be 1, 2, 3, ...., 20, respectively. Then I want to keep the window size of 20 afterwards. How this can be done?
Here is the sample data and desired output with window size 3:
Days Original_Values Desired_Output
1 2 2
2 4 2
3 1 3
4 3 7/3
5 5 8/3
6 6 9/3
7 4 14/3
8 9 15/3