Im using this as an example (Calculating moving average) which I have successfully incorporated into my code. I need to calculate rolling mean and rolling median (which I have done) but my data set is enormous and I need to add a secondary variable to filter this by. In the example below, they calculate rolling mean for a data set of 10 days. What happens if they have 10 days for different locations, and we need to calculate the rolling means for 10 days based on these different location?
library(tidyverse)
library(zoo)
some_data = tibble(day = 1:10)
# cma = centered moving average
# tma = trailing moving average
some_data = some_data %>%
mutate(roll_mean = rollmean(day, k = 3, fill = NA)) %>%
mutate(roll_median = rollmedian(day, k = 3, fill = NA, align = "right"))
some_data