library(MazamaRollUtils)
# Example air quality time series
t <- example_pm25$datetime
x <- example_pm25$pm25
plot(t, x, pch = 16, cex = 0.5)
lines(t, roll_median(x, width = 3), col = "goldenrod")
lines(t, roll_median(x, width = 23), col = "purple")
legend("topright", lty = c(1, 1),
col = c("goldenrod", "purple"),
legend = c("3-hr median", "12-hr median"))
title("3- and 23-hr Rolling median")
Run the code above in your browser using DataLab