Description Usage Arguments Examples
Apply a function along a vector or a list
1 2 3 |
obj |
A list or an atomic vector. |
fun |
A function to be applied. |
w |
Width of the window. |
... |
Optional arguments to |
wty |
Window type: to choose between |
simplify |
Logical or character string. Should the result be simplified to a vector, matrix or higher dimensional array if possible? |
aty |
Argument type: How the elements of |
nas |
Should NAs be added to the result to match the length of the input. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | x <- seq(1, 3, length = 150) + rt(150, df = 2) / 3
plot(x)
av <- rollapply(x, mean, 15)
lines(av, lwd = 2)
err <- rollapply(x, sd, 15)
lines(av + err, lwd = 2, lty = 2) ; lines(av - err, lwd = 2, lty = 2)
# 'wty' argument
lines(rollapply(x, mean, wty = 'f'), type = 's', col = 'red')
# 'aty' argument
x <- 2^(0:5)
out <- rollapply(x, seq, 2, aty = 'm')
names(out) <- rollapply(x, paste, 2, sep = ':', aty = 'm')
out
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.