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_max(x, width = 12), col = 'red')
lines(t, roll_min(x, width = 12), col = 'deepskyblue')
title("12-hr Rolling Max and Min")
plot(t, x, pch = 16, cex = 0.5)
points(t, roll_min(x, width = 12, na.rm = TRUE),
pch = 16, col = 'deepskyblue')
points(t, roll_min(x, width = 12, na.rm = FALSE),
pch = 16, col = adjustcolor('black', 0.4))
legend("topright", pch = c(16, 16),
col = c("deepskyblue", adjustcolor("black", 0.4)),
legend = c("na.rm = TRUE", "na.rm = FALSE"))
title("12-hr Rolling min with/out na.rm")
Run the code above in your browser using DataLab