| stretch2 {tsibble} | R Documentation |
Fixing an initial window and expanding more observations:
stretch2() and pstretch() always returns a list.
stretch2_lgl(), stretch2_int(), stretch2_dbl(), stretch2_chr() use the same
arguments as stretch2(), but return vectors of the corresponding type.
stretch2_dfr() stretch2_dfc() return data frames using row-binding & column-binding.
stretch2(.x, .y, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE) stretch2_dfr(.x, .y, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE, .id = NULL) stretch2_dfc(.x, .y, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE) pstretch(.l, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE) pstretch_dfr(.l, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE, .id = NULL) pstretch_dfc(.l, .f, ..., .step = 1, .init = 1, .fill = NA, .bind = FALSE)
.x |
Objects to slide over simultaneously. |
.y |
Objects to slide over simultaneously. |
.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 calculating at every specified step instead of every single 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 |
.l |
A list of vectors, such as a data frame. The length of |
slide2 for sliding window with overlapping observations
tile2 for tiling window without overlapping observations
Other stretching window functions: stretch
x <- 1:5
y <- 6:10
z <- 11:15
lst <- list(x = x, y = y, z = z)
df <- as.data.frame(lst)
stretch2(x, y, sum, .step = 2)
stretch2(lst, lst, ~ ., .step = 2)
stretch2(df, df, ~ ., .step = 2)
pstretch(lst, sum, .step = 1)
pstretch(list(lst, lst), ~ ., .step = 2)
###
# row-wise stretching over data frame
###
x <- as.Date("2017-01-01") + 0:364
df <- data.frame(x = x, y = seq_along(x))
tibble(
data = pstretch(df, function(...) as_tibble(list(...)), .init = 10)
)