| stretch {tsibble} | R Documentation |
Fixing an initial window and expanding more observations:
stretch() always returns a list.
stretch_lgl(), stretch_int(), stretch_dbl(), stretch_chr() use the same
arguments as stretch(), but return vectors of the corresponding type.
stretch_dfr() stretch_dfc() return data frames using row-binding & column-binding.
stretch(.x, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE) stretch_dfr(.x, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE, .id = NULL) stretch_dfc(.x, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE)
.x |
An object to slide over. |
.f |
A function, formula, or vector (not necessarily atomic). If a function, it is used as is. If a formula, e.g.
This syntax allows you to create very compact anonymous functions. If character vector, numeric vector, or list, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of |
... |
Additional arguments passed on to the mapped function. |
.step |
A positive integer for incremental step. |
.init |
A positive integer for an initial window size. |
.fill |
A value to fill at the left/center/right of the data range depending
on |
.bind |
If |
.id |
Either a string or Only applies to |
if .fill != NULL, it always returns the same length as input.
future_stretch for stretching window in parallel
slide for sliding window with overlapping observations
tile for tiling window without overlapping observations
Other stretching window functions: stretch2
x <- 1:5 stretch_dbl(x, mean, .step = 2) stretch_lgl(x, ~ mean(.) > 2, .step = 2) lst <- list(x = x, y = 6:10, z = 11:15) stretch(lst, ~ ., .step = 2, .fill = NULL)