Learn R Programming

tsibble (version 1.2.0)

update_tsibble: Update key and index for a tsibble

Description

Update key and index for a tsibble

Usage

update_tsibble(
  x,
  key,
  index,
  regular = is_regular(x),
  validate = TRUE,
  .drop = key_drop_default(x)
)

Arguments

x

A tsibble.

key

<tidy-select> Variable(s) that uniquely determine time indices. NULL for an empty key, unquoted column names (e.g. x) for a single variable, and c() for multiple variables (e.g. c(x, y)). This argument also supports tidy-select expressions, e.g. dplyr::starts_with(), dplyr::all_of().

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.

regular

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

validate

TRUE suggests 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, specify FALSE to skip the checks.

.drop

If TRUE, empty key groups are dropped.

Details

Unspecified arguments will inherit the attributes from x.

Examples

Run this code
# update index
library(dplyr)
pedestrian %>%
  group_by_key() %>%
  mutate(Hour_Since = Date_Time - min(Date_Time)) %>%
  update_tsibble(index = Hour_Since)

# update key: drop the variable "State" from the key
tourism %>%
  update_tsibble(key = c(Purpose, Region))

Run the code above in your browser using DataLab