Description Usage Arguments Details Value See Also Examples
These functions are specialized variants of the most common ways that
slide_index()
is generally used. Notably, slide_index_sum()
can be used
for rolling sums relative to an index (like a Date column), and
slide_index_mean()
can be used for rolling averages.
These specialized variants are much faster and more memory efficient than
using an otherwise equivalent call constructed with slide_index_dbl()
or slide_index_lgl()
, especially with a very wide window.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  slide_index_sum(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_prod(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_mean(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_min(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_max(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_all(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)
slide_index_any(
x,
i,
...,
before = 0L,
after = 0L,
complete = FALSE,
na_rm = FALSE
)

x 
A vector to compute the sliding function on.

i 
The index vector that determines the window sizes. It is fairly common to supply a date vector as the index, but not required. There are 3 restrictions on the index:

... 
These dots are for future extensions and must be empty. 
before 
The ranges that result from applying 
after 
The ranges that result from applying 
complete 
Should the function be evaluated on complete windows only? If 
na_rm 
Should missing values be removed from the computation? 
For more details about the implementation, see the help page of
slide_sum()
.
A vector the same size as x
containing the result of applying the
summary function over the sliding windows.
For sliding sum, mean, prod, min, and max, a double vector will be returned.
For sliding any and all, a logical vector will be returned.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  x < c(1, 5, 3, 2, 6, 10)
i < as.Date("20190101") + c(0, 1, 3, 4, 6, 8)
# `slide_index_sum()` can be used for rolling sums relative to an index,
# allowing you to "respect gaps" in your series. Notice that the rolling
# sum in row 3 is only computed from `20190104` and `20190102` since
# `20190101` is more than two days before the current date.
data.frame(
i = i,
x = x,
roll = slide_index_sum(x, i, before = 2)
)
# `slide_index_mean()` can be used for rolling averages
slide_index_mean(x, i, before = 2)
# Only evaluate the sum on windows that have the potential to be complete
slide_index_sum(x, i, before = 2, after = 1, complete = TRUE)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.