Data Transformation: Moving Window Smoothing of Zoo Time Series
Source:R/transformations.R
f_smooth_window.Rd
Simplified wrapper to zoo::rollapply()
to apply rolling window smoothing to zoo objects.
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
, andsd
. 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...
inzoo::rollapply()
.
See also
Other tsl_transformation:
f_center()
,
f_detrend_difference()
,
f_detrend_linear()
,
f_hellinger()
,
f_list()
,
f_pca()
,
f_percentage()
,
f_proportion()
,
f_rescale()
,
f_scale()
,
f_slope()
,
f_trend_linear()
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)
}