ma | R Documentation |
This function calculates a simple moving average
ma(x, d, na.rm = FALSE)
x |
A numeric vector |
d |
Window size |
na.rm |
Use a shorter window size for the first values? See "Return Value". |
A vector of the same length as x. If na.rm=FALSE
(the default),
the first d-1
places of the return vector are NA
. If na.rm=TRUE
,
a moving average is calculated for these with a shorter window size.
ma(1:6, 3)
# Returns NA NA 2 3 4 5
ma(1:6, 3, na.rm=TRUE)
# Returns 1.0 1.5 2.0 3.0 4.0 5.0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.