I have the following dataframe:
agrodata
week temperature humidity radiation evapotranspiration
<date> <dbl> <dbl> <dbl> <dbl>
2012-03-25 15.9 54.1 20.4 0
2012-06-17 25.9 65.6 22.2 0.486
2012-06-24 27.4 61.7 21.3 0
2012-07-08 27.5 62.9 22.4 0
2012-07-15 27.5 50.1 23.1 0
2012-07-22 27.0 56.4 19.0 0
2012-07-29 28.7 61.5 19.7 0
2012-08-05 29.1 56.1 20.0 0.0286
2012-08-12 28.6 56.8 19.4 0
2012-08-19 29.0 63.0 18.1 0
2012-08-26 27.4 62.9 18.0 0.229
2012-09-02 16.9 32.9 16.9 0
2012-09-09 25.0 62.1 16.7 0
2012-09-16 25.4 62.6 14.5 0
2012-09-30 22.3 65.6 15.2 0
2012-10-07 22.4 71.4 13.9 0
2012-10-14 19.3 67.2 11.3 0.257
2012-10-21 18.7 74.5 9.70 3.43
2012-10-28 16.4 75.5 8.35 3.2
2012-11-04 17.8 79.7 7.17 7
As you can see I have the date grouped by weeks. I want to create 4 new columns (for each one of the 4 climate variables) containing the mean of the previous 5 consecutive weeks, and if there aren't 5 previous consecutive weeks, then whatever are... Is there some way to do it with dplyr? Thank you.