Manipulating Time Series Data in R
Harrison Brown
Graduate Researcher in Geography
zoo::roll*:
rollmean()rollmax()rollsum()Limitations:
rollmin()!rollapply(data = ftse,
width = 7,
FUN = min,
align = 'right',
fill = NA)
Arguments:
data: Time series objectwidth: Width of window (k)FUN: Summary function (mean, max, ...)align: Window alignment ('left', 'right', or 'center')fill: Values to fill in outside of windowGoal:
daily_temp
2019-01-01 13.191304
2019-01-02 6.945833
2019-01-03 8.495833
2019-01-04 8.683333
2019-01-05 7.400000
...
find_range <- function(x){
max(x) - min(x)
}
daily_temp_range <-
rollapply(
daily_temp,
FUN = find_range,
width = 30,
align = 'right',
fill = NA
)
autoplot(daily_temp_range) +
theme_light() +
labs(y = 'Temperature Range')

Manipulating Time Series Data in R