Learn R Programming

tsibble (version 0.2.0)

stretch: Stretching window calculation

Description

Fixing an initial window and expanding more observations:

  • stretch() always returns a vector of numerics

  • stretch_lst() returns a list

  • stretch_dfr() return data frame using row-binding

  • stretcher() splits the input x to a list according to the window size.

Usage

stretch(x, .f, ..., size = 1, init = 1)

stretch_lst(x, .f, ..., size = 1, init = 1)

stretch_dfr(x, .f, ..., size = 1, init = 1, .id = NULL)

stretcher(x, size = 1, init = 1)

Arguments

x

A vector of numerics, or data frame. If a data frame, row-wise rolling window is performed.

.f

A function or one-sided formula using purrr-like syntax. If a formula, it is converted to a function.

...

Additional arguments passed on to .f.

size, init

An integer for moving and initial window size.

.id

If not NULL a variable with this name will be created giving either the name or the index of the data frame, which is passed to dplyr::bind_rows.

See Also

slide for sliding window with overlapping observations; tile for tiling window without overlapping observations.

Examples

Run this code
# NOT RUN {
x <- 1:10
stretch(x, mean, init = 3)
stretch(x, ~ mean(.), init = 3)
stretcher(x, init = 3)

# stretching a 2-day window for a data frame ----
sx <- pedestrian %>% 
  filter(Sensor == "Southern Cross Station", Date <= as.Date("2015-01-10"))
sx %>%
  stretch_dfr(~ quantile(.$Count), init = 48)
# }

Run the code above in your browser using DataLab