I'd like to take a vector of numerics, then using a specified window width & stride I want to run down through the vector capturing the means of each window by their stride. I can code this but I'm wondering if there's a neater way with a package etc..?

One way to achieve what you need is by using rollapply from zoo package.
library(zoo)
rollapply(x, width = 7, by = 4, mean)
#[1] 622.1429 682.8571 540.7143
DATA
x <-c(267, 497, 836, 498, 923, 836, 498, 923, 267, 497, 836, 498, 923, 267, 497)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With