Create a tsibble object

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



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


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.


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


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


A tsibble object.


A tsibble is sorted by its key first and index.


The time indices are no longer an attribute (for example, the tsp attribute in a ts object), but preserved as the essential component of the tsibble. 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. zoo::yearmth and zoo::yearqtr are also supported. 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::yearmth, 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 variable(s) together with the index uniquely identifies each record. And key(s) also imposes the structure on a tsibble, which can be created via the id function as identifiers:

  • None: an implicit variable id() resulting a univariate time series.

  • A single variable: an explicit variable. For example, data(pedestrian) uses the id(Sensor) column as the key.

  • Nested variables: a nesting of one variable under another. For example, data(tourism) contains two geographical locations: Region and State. Region is the lower level than State in Australia; in other words, Region is nested into State, which naturally forms a hierarchy. A vertical bar (|) is used to describe this nesting relationship, and thus Region | State. In theory, nesting can involve infinite levels, so is tsibble.

  • Crossed variables: a crossing of one variable with another. For example, the geographical locations are crossed with the purpose of visiting (Purpose) in the data(tourism). A comma (,) is used to indicate this crossing relationship. Nested and crossed variables can be combined, such as data(tourism) using id(Region | State, Purpose).

These key variables describe the data structure.


The interval function returns the interval associated with the tsibble.

  • Regular: the value and its time unit including "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/yearmth: "month"

  • yearweek: "week"

  • Date: "day"

  • POSIXct & nanotime: "hour", "minute", "second"

See also


# create a tsibble w/o a key ---- tsbl1 <- tsibble( date = seq(as.Date("2017-01-01"), as.Date("2017-01-10"), by = 1), value = rnorm(10), key = id(), index = date ) tsbl1
#> # A tsibble: 10 x 2 [1DAY] #> date value #> <date> <dbl> #> 1 2017-01-01 0.0645 #> 2 2017-01-02 -0.265 #> 3 2017-01-03 -0.447 #> 4 2017-01-04 -1.41 #> 5 2017-01-05 -0.506 #> 6 2017-01-06 -0.270 #> 7 2017-01-07 -1.09 #> 8 2017-01-08 0.362 #> 9 2017-01-09 -0.336 #> 10 2017-01-10 1.36
# create a tsibble with one key ---- tsbl2 <- tsibble( qtr = rep(yearquarter(seq(2010, 2012.25, by = 1 / 4)), 3), group = rep(c("x", "y", "z"), each = 10), value = rnorm(30), key = id(group), index = qtr ) tsbl2
#> # A tsibble: 30 x 3 [1QUARTER] #> # Key: group [3] #> qtr group value #> <qtr> <chr> <dbl> #> 1 2010 Q1 x -0.712 #> 2 2010 Q2 x 0.662 #> 3 2010 Q3 x 0.291 #> 4 2010 Q4 x 0.198 #> 5 2011 Q1 x -1.20 #> 6 2011 Q2 x -0.0398 #> 7 2011 Q3 x 0.687 #> 8 2011 Q4 x 0.705 #> 9 2012 Q1 x 0.991 #> 10 2012 Q2 x 1.14 #> # ... with 20 more rows