Create a tsibble object

tsibble(..., key = id(), index, regular = TRUE)

Arguments

...

A set of name-value pairs. The names of "key" and "index" should be avoided as they are used as the arguments.

key

Variable(s) that define unique time indices, used in conjunction with the helper id(). If a univariate time series (without an explicit key), simply call id().

index

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

regular

Regular time interval (TRUE) or irregular (FALSE). The interval is determined by the greatest common divisor of index column, if TRUE.

Value

A tsibble object.

Details

A tsibble is sorted by its key first and index.

Index

The time indices are preserved as the essential data component of the tsibble, instead of implicit attribute (for example, the tsp attribute in a ts object). A few index classes, such as Date, POSIXct, and difftime, forms the basis of the tsibble, with new additions yearweek, yearmonth, and yearquarter representing year-week, year-month, and year-quarter respectively. Any arbitrary index class are also supported, including zoo::yearmon, zoo::yearqtr, and nanotime. For a tbl_ts of regular interval, a choice of index representation has to be made. For example, a monthly data should correspond to time index created by yearmonth or zoo::yearmon, instead of Date or POSIXct. Because months in a year ensures the regularity, 12 months every year. However, if using Date, a month contains days ranging from 28 to 31 days, which results in irregular time space. This is also applicable to year-week and year-quarter.

Since the tibble that underlies the tsibble only accepts a 1d atomic vector or a list, a tbl_ts doesn't accept POSIXlt and timeDate columns.

Key

Key variable(s) together with the index uniquely identifies each record, which can be created via the id function as identifiers:

Interval

The interval function returns the interval associated with the tsibble.

  • Regular: the value and its time unit including "nanosecond", "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "year". An unrecognisable time interval is labelled as "unit".

  • Irregular: as_tsibble(regular = FALSE) gives the irregular tsibble. It is marked with !.

  • Unknown: if there is only one entry for each key variable, the interval cannot be determined (?).

An interval is obtained based on the corresponding index representation:

  • integer/numeric: either "unit" or "year"

  • yearquarter/yearqtr: "quarter"

  • yearmonth/yearmon: "month"

  • yearweek: "week"

  • Date: "day"

  • POSIXct: "hour", "minute", "second", "millisecond", "microsecond"

  • nanotime: "nanosecond"

See also

Examples

# create a tsibble w/o a key ---- tsibble( date = as.Date("2017-01-01") + 0:9, value = rnorm(10) )
#> Column `date` is the index.
#> # A tsibble: 10 x 2 [1D] #> date value #> <date> <dbl> #> 1 2017-01-01 1.14 #> 2 2017-01-02 -1.24 #> 3 2017-01-03 2.65 #> 4 2017-01-04 -0.157 #> 5 2017-01-05 -0.423 #> 6 2017-01-06 -0.198 #> 7 2017-01-07 -0.895 #> 8 2017-01-08 0.904 #> 9 2017-01-09 0.0796 #> 10 2017-01-10 -1.26
# create a tsibble with one key ---- tsibble( qtr = rep(yearquarter("201001") + 0:9, 3), group = rep(c("x", "y", "z"), each = 10), value = rnorm(30), key = id(group) )
#> Column `qtr` is the index.
#> # A tsibble: 30 x 3 [1Q] #> # Key: group [3] #> qtr group value #> <qtr> <chr> <dbl> #> 1 2010 Q1 x 1.03 #> 2 2010 Q2 x -0.731 #> 3 2010 Q3 x -0.190 #> 4 2010 Q4 x 0.529 #> 5 2011 Q1 x 0.550 #> 6 2011 Q2 x 0.550 #> 7 2011 Q3 x -0.660 #> 8 2011 Q4 x 0.0574 #> 9 2012 Q1 x -2.81 #> 10 2012 Q2 x -0.912 #> # … with 20 more rows