View source: R/moving_average.R
moving_average | R Documentation |
Functions to calculate a moving average. These are useful to get rid of (strong) peakiness.
moving_average(x, w, side = "centre", na.rm = getOption("na.rm", FALSE))
moving_sum(x, w, side = "centre", na.rm = getOption("na.rm", FALSE))
moving_Q1(x, w, side = "centre", na.rm = getOption("na.rm", FALSE))
moving_Q3(x, w, side = "centre", na.rm = getOption("na.rm", FALSE))
moving_fn(x, w, fun, side = "centre", ...)
x |
vector of values |
w |
window length; total number of observations to include. This should preferably be an odd number, so that the same number of values to the left and right of |
side |
default is |
na.rm |
a logical to indicate whether empty must be removed from |
fun |
function to apply |
... |
arguments passed on to |
Each function can be used over a moving period with moving_fn()
. For example, for a moving median: moving_fn(x, 7, fun = median)
. Or a moving maximum: moving_fn(x, 5, fun = max)
.
The moving average is determined by averaging floor(w / 2)
values before and after each element of x
and all elements in between.
na.rm
This 'certestats' package supports a global default setting for na.rm
in many mathematical functions. This can be set with options(na.rm = TRUE)
or options(na.rm = FALSE)
.
For normality()
, quantile()
and IQR()
, this also applies to the type
argument. The default, type = 7
, is the default of base R. Use type = 6
to comply with SPSS.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.