Description Usage Arguments Value Examples
Apply rolling operations over a moving window for size n
and increment step
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
x |
Univariate vector, numeric or ts object with only one dimension. |
n |
Window size. |
step |
Rolling window step. |
align |
Specifying whether the index of the result should be left- or right-aligned or centered (default) compared to the rolling window of observations. |
fn |
|
fill |
Numeric value(s) or function used to fill observations. |
... |
Further arguments passed to the function |
roll()
: returns a vector with the same class and attributes as the input vector.
roll_idx()
: Returns the index that is used to calculate the subsets.
roll_data()
: Returns a list subsets of length length(x)/step.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # x is odd
roll_idx(1:9, 2, 1, align = "left")
roll_idx(1:9, 2, 1, align = "center")
roll_idx(1:9, 2, 1, align = "right") # reduces
# This works
roll_idx(1:9, 3, 1, align = "left")
roll_idx(1:9, 3, 1, align = "center")
roll_idx(1:9, 3, 1, align = "right")
roll_idx(1:9, 2, 2, align = "left")
roll_idx(1:9, 2, 2, align = "center")
roll_idx(1:9, 2, 2, align = "right")
roll_idx(1:9, 3, 2, align = "left")
roll_idx(1:9, 3, 2, align = "center")
roll_idx(1:9, 3, 2, align = "right") # reduces
# x is even
roll_idx(1:8, 2, 2, align = "left")
roll_idx(1:8, 2, 2, align = "center")
roll_idx(1:8, 2, 2, align = "right") # reduces
roll_idx(1:8, 2, 1, align = "left")
roll_idx(1:8, 2, 1, align = "center")
roll_idx(1:8, 2, 1, align = "right")
roll_idx(1:8, 3, 1, align = "left")
roll_idx(1:8, 3, 1, align = "center")
roll_idx(1:8, 3, 1, align = "right") # reduces
roll_idx(1:8, 3, 1, align = "left")
roll_idx(1:8, 3, 1, align = "center")
roll_idx(1:8, 3, 1, align = "right") # reduces
x <- seq(10, 1, -1)
roll_data(x, 2, align = "left")
roll_data(x, 2, align = "right")
roll(x, max, 3)
roll(x, max, 3, align = "right")
x <- 1:6
roll_data(x, 2)
roll(x, mean, 2)
roll_data(x, 2, 2)
roll(x, mean, 2, 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.