slide_tsibble: Perform sliding windows on a tsibble by row

View source: R/rolling.R

slide_tsibbleR Documentation

Perform sliding windows on a tsibble by row

Description

\lifecycle

questioning

Usage

slide_tsibble(.x, .size = 1, .step = 1, .id = ".id")

Arguments

.x

A tsibble.

.size

A positive integer for window size.

.step

A positive integer for calculating at every specified step instead of every single step.

.id

A character naming the new column .id containing the partition.

Rolling tsibble

slide_tsibble(), tile_tsibble(), and stretch_tsibble() provide fast and shorthand for rolling over a tsibble by observations. That said, if the supplied tsibble has time gaps, these rolling helpers will ignore those gaps and proceed.

They are useful for preparing the tsibble for time series cross validation. They all return a tsibble including a new column .id as part of the key. The output dimension will increase considerably with slide_tsibble() and stretch_tsibble(), which is likely to run out of memory when the data is large.

See Also

Other rolling tsibble: stretch_tsibble(), tile_tsibble()

Examples

harvest <- tsibble(
  year = rep(2010:2012, 2),
  fruit = rep(c("kiwi", "cherry"), each = 3),
  kilo = sample(1:10, size = 6),
  key = fruit, index = year
)
harvest %>%
  slide_tsibble(.size = 2)

tidyverts/tsibble documentation built on Feb. 7, 2024, 5:11 a.m.