Creating a trailing rolling average without NAs at the beginning of the output
I’m working with a nested dataframe using dplyr. I need to mutate a second nested column with a copy of the data where all numeric columns are replaced with a trailing rolling average of the last 5 rows.
rolling weighted mean by group with zoo and dplyr
I need to calculate the moving, weighted average by group in R.
Return NA for conditional lead/lagged rolling sum if window outside dataframe or group
I need to get the sum of values from column x either side of every 1 in column y. The windows are 1:4 and 5:8 before and after each occurrence of 1 in y. However, if the windows are beyond the limits of the df, 0 is returned. This is an issue as it is possible that 0 could be a valid result. The full data have multiple groups (id) but hopefully this repex is enough help create a scalable solution.
Return NA for conditional lead/lagged rolling sum if window outside dataframe or group
I need to get the sum of values from column x either side of every 1 in column y. The windows are 1:4 and 5:8 before and after each occurrence of 1 in y. However, if the windows are beyond the limits of the df, 0 is returned. This is an issue as it is possible that 0 could be a valid result. The full data have multiple groups (id) but hopefully this repex is enough help create a scalable solution.