Description Usage Arguments Details Methods (by class) Examples
View source: R/rolling_apply.R
Apply a function to the time series values in a half-open (open on the left, closed on the right) rolling time window of fixed temporal width.
1 2 3 4 5 | rolling_apply(x, ...)
## S3 method for class 'uts'
rolling_apply(x, width, FUN, ..., by = NULL, align = "right",
interior = FALSE, use_specialized = TRUE)
|
x |
a numeric time series object. |
... |
arguments passed to |
width |
a finite, positive |
FUN |
a function to be applied to the vector of observation values inside the half-open rolling time window. |
by |
a positive |
align |
either |
interior |
logical. If |
use_specialized |
logical. Whether to use a fast optimized implementation, if available. Currently, the following choices for |
A fast optimized implementation is used automatically for certain choices of FUN
. See the use_specialized
argument for details.
uts
: apply rolling function to "uts"
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # rolling mean, sum, number of observations
rolling_apply(ex_uts(), width=ddays(1), FUN=mean)
rolling_apply(ex_uts(), width=ddays(1), FUN=sum)
rolling_apply(ex_uts(), width=ddays(1), FUN=length)
# move rolling time window by one observation vs. one day at a time
rolling_apply(ex_uts(), width=ddays(1), FUN="mean")
rolling_apply(ex_uts(), width=ddays(1), FUN="mean", by=ddays(1))
# right-align, left-aligned, and centered rolling time window
rolling_apply(ex_uts(), width=ddays(1), FUN=mean)
rolling_apply(ex_uts(), width=ddays(1), FUN=mean, align="left")
rolling_apply(ex_uts(), width=ddays(1), FUN=mean, align="center")
# restrict rolling time window to temporal support of x
rolling_apply(ex_uts(), width=ddays(1), FUN="mean", interior=TRUE)
# specialized vs. general-purpose implementation
rolling_apply(ex_uts(), width=ddays(1), FUN="mean")
rolling_apply(ex_uts(), width=ddays(1), FUN="mean", use_specialized=FALSE) # same
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.