Hi, is it possible to calculate a rolling mean with dplyr? I am thinking the lag function might help here. But not sure how to actually do it. Thanks!
dplyr
lag
You can try the slider package, it is dplyr friendly
slider
If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.
I use something like
tibble(time = 1:10, value = rnorm(10)) %>% arrange(time) %>% mutate(rolling_avg = cumsum(value) / row_number())
The arrange is unnecessary in this example, but in general you want to guarantee a specific ordering.
arrange
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.