Moving functions
Helper function to compute 'moving' functions, such as the 'moving average'
movingFun(x, n, fun=mean, type='around', circular=FALSE, na.rm=FALSE)
x |
A vector of numbers |
n |
Size of the 'window', i.e. the number of sequential elements to use in the function |
fun |
A function like mean, min, max, sum |
type |
Character. One of 'around', 'to', or 'from'. The choice indicates which values should be used in the computation. The focal element is always used. If |
circular |
Logical. If |
na.rm |
Logical. If |
Numeric
Robert J. Hijmans, inspired by Diethelm Wuertz' rollFun function in the fTrading package
movingFun(1:12, 3, mean) movingFun(1:12, 3, mean, 'to') movingFun(1:12, 3, mean, 'from') movingFun(1:12, 3, mean, circular=TRUE) v <- c(0,1,2,3,3,3,3,4,4,4,5,5,6,7,7,8,9,NA) movingFun(v, n=5) movingFun(v, n=5, na.rm=TRUE)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.