Learn R Programming

tsibble (version 0.1.0)

stretch: Stretching window calculation

Description

stretch() is an S3 method to carry out expanding window calculation; stretcher() splits the input x to a list according to the window size.

Usage

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

# S3 method for default stretch(x, .f, ..., size = 1, init = 1)

# S3 method for data.frame stretch(x, .f, ..., size = 1, init = 1, deframe = TRUE)

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

Arguments

x

A vector of numerics, or data frame.

.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.

deframe

TRUE a list is returned. FALSE returns a data frame.

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(~ quantile(.$Count), init = 48, deframe = FALSE)
# }

Run the code above in your browser using DataLab