Learn R Programming

tsibble (version 0.2.0)

build_tsibble: Construct a tsibble object

Description

A relatively more controllable function to create a tbl_ts object. It is useful for creating a tbl_ts internally inside a function, and it allows users to determine if the time needs ordering and the interval needs calculating.

Usage

build_tsibble(x, key, index, index2, groups = id(), regular = TRUE,
  validate = TRUE, ordered = NULL, interval = NULL)

Arguments

x

A data.frame, tbl_df, tbl_ts, or other tabular objects.

key

Structural variable(s) that define unique time indices, used with the helper id. If a univariate time series (without an explicit key), simply call id(). See below for details.

index

A bare (or unquoted) variable to specify the time index variable.

index2

A candidate of index to update the index to a new one when index_by. By default, it's identical to index.

groups

Grouping variable(s) when group_by.tbl_ts.

regular

Regular time interval (TRUE) or irregular (FALSE). TRUE finds the greatest common divisor of positive time distances as the interval.

validate

TRUE suggests to verify that each key or each combination of key variables lead to unique time indices (i.e. a valid tsibble). It will also make sure that the nested variables are arranged from lower level to higher, if nested variables are passed to key. If you are sure that it's a valid input, specify FALSE to skip the checks.

ordered

The default of NULL arranges the key variable(s) first and then index in ascending order. TRUE suggests to skip the ordering as x in the correct order. FALSE also skips the ordering but gives a warning instead.

interval

NULL computes the interval. Use the specified interval as is, if an class of interval is supplied.

Examples

Run this code
# NOT RUN {
# Prepare `pedestrian` to use a new index `Date` ----
pedestrian %>%
  build_tsibble(
    key = key(.), index = !! index(.), index2 = Date, interval = interval(.)
  )
# }

Run the code above in your browser using DataLab