Skip to contents

Simplified wrapper to zoo::rollapply() to apply rolling window smoothing to zoo objects.

Usage

f_smooth_window(x = NULL, smoothing_window = 3, smoothing_f = mean, ...)

Arguments

x

(required, zoo object) Zoo time series object to transform. Default: NULL

smoothing_window

(required, odd integer) Width of the window to compute the rolling statistics of the time series. Should be an odd number. Even numbers are coerced to odd by adding one. Default: 3

smoothing_f

(required, function) name without quotes and parenthesis of a standard function to smooth a time series. Typical examples are mean (default), max, mean, median, and sd. Custom functions able to handle zoo objects or matrices are also allowed. Default: mean.

...

(optional, additional arguments) additional arguments to smoothing_f. Used as argument ... in zoo::rollapply().

Value

zoo object

Examples

x <- zoo_simulate(cols = 2)

y <- f_smooth_window(
  x = x,
  smoothing_window = 5,
  smoothing_f = mean
)

if(interactive()){
  zoo_plot(x)
  zoo_plot(y)
}