I am trying to get a rolling average of every third (or second) row in a specific column. More precisely I want to have the rolling average stored in a new variable in my existing dataframe.
I tried to use this function:
w %>%
mutate(rmean = roll_meanl(SWI_001, 3)) %>%
filter(between(date, 2, 4)) %>%
select(-date)
I want the rolling average of every third row of variable SWI_001. The new variable with the data should be roll_mean1.
But I am not sure how to filter it properly.
My dataframe (w) looks like this, however has 255 rows in total and almost 50 columns:
Date ASS_SUB ASS_TOP SWI_001 SWI_005 SWI_010 SWI_100 B1_005 B1_015 B1_025 B1_035 B1_045 B1_055 B1_065
1: 06.11.2018 17.37 14.16 15.54 NA 15.57 NA NA NA NA NA NA NA NA
2: 07.11.2018 17.32 13.90 15.21 NA 15.51 NA 14.4 14.8 14.8 14.8 14.8 14.8 14.8
3: 08.11.2018 17.29 13.77 14.75 NA 15.39 NA 14.2 14.8 14.8 14.8 14.8 14.8 14.8
4: 09.11.2018 17.27 13.64 15.05 NA 15.38 NA 14.0 14.8 14.8 14.8 14.8 14.8 14.8
5: 10.11.2018 17.24 13.64 14.89 NA 15.30 NA 13.9 14.8 14.8 14.8 14.8 14.8 14.8
---
In the end I need the rolling mean for more than just one column, but to get started I am happy for a nudge in the right direction.