build_tsibble() creates a tbl_ts object with more controls. It is useful
for creating a tbl_ts internally inside a function, and it allows developers to
determine if the time needs ordering and the interval needs calculating.
Usage
build_tsibble(
x,
key = NULL,
key_data = NULL,
index,
index2 = index,
ordered = NULL,
interval = TRUE,
validate = TRUE,
.drop = key_drop_default(x)
)Arguments
- x
A
data.frame,tbl_df,tbl_ts, or other tabular objects.- key
<
tidy-select> Variable(s) that uniquely determine time indices.NULLfor an empty key, unquoted column names (e.g.x) for a single variable, andc()for multiple variables (e.g.c(x, y)). This argument also supports tidy-select expressions, e.g.dplyr::starts_with(),dplyr::all_of().- key_data
A data frame containing key variables and
.rows. When a data frame is supplied, the argumentkeywill be ignored.- index
<
tidy-select> A variable that contains time indices. This is commonly an unquoted column name (e.g.t), but it can also be a tidy-select expression.- index2
A candidate of
indexto update the index to a new one when index_by. By default, it's identical toindex.- ordered
The default of
NULLarranges the key variable(s) first and then index from past to future.TRUEsuggests to skip the ordering asxin the correct order.FALSEchecks the ordering and may give a warning.- interval
TRUEautomatically calculates the interval, andFALSEfor irregular interval. Use the specified interval vianew_interval()as is.- validate
TRUEsuggests to verify that each key or each combination of key variables leads to unique time indices (i.e. a valid tsibble). If you are sure that it's a valid input, specifyFALSEto skip the checks.- .drop
If
TRUE, empty key groups are dropped.
Examples
# Prepare `pedestrian` to use a new index `Date` ----
pedestrian %>%
build_tsibble(
key = !!key_vars(.), index = !!index(.), index2 = Date,
interval = interval(.)
)
#> # A tsibble: 66,037 x 5 [1h] <Australia/Melbourne>
#> # Key: Sensor [4]
#> # Groups: @ Date [731]
#> Sensor Date_Time Date Time Count
#> <chr> <dttm> <date> <int> <int>
#> 1 Birrarung Marr 2015-01-01 00:00:00 2015-01-01 0 1630
#> 2 Birrarung Marr 2015-01-01 01:00:00 2015-01-01 1 826
#> 3 Birrarung Marr 2015-01-01 02:00:00 2015-01-01 2 567
#> 4 Birrarung Marr 2015-01-01 03:00:00 2015-01-01 3 264
#> 5 Birrarung Marr 2015-01-01 04:00:00 2015-01-01 4 139
#> 6 Birrarung Marr 2015-01-01 05:00:00 2015-01-01 5 77
#> 7 Birrarung Marr 2015-01-01 06:00:00 2015-01-01 6 44
#> 8 Birrarung Marr 2015-01-01 07:00:00 2015-01-01 7 56
#> 9 Birrarung Marr 2015-01-01 08:00:00 2015-01-01 8 113
#> 10 Birrarung Marr 2015-01-01 09:00:00 2015-01-01 9 166
#> # ℹ 66,027 more rows
