aggregate_key: Expand a dataset to include other levels of aggregation

View source: R/aggregate.R

aggregate_keyR Documentation

Expand a dataset to include other levels of aggregation

Description

Uses the structural specification given in .spec to aggregate a time series. A grouped structure is specified using grp1 * grp2, and a nested structure is specified via parent / child. Aggregating the key structure is commonly used with forecast reconciliation to produce coherent forecasts over some hierarchy.

Usage

aggregate_key(.data, .spec, ...)

Arguments

.data

A tsibble.

.spec

The specification of aggregation structure.

...

<data-masking> Name-value pairs of summary functions. The name will be the name of the variable in the result.

The value can be:

  • A vector of length 1, e.g. min(x), n(), or sum(is.na(y)).

  • A data frame, to add multiple columns from a single expression.

[Deprecated] Returning values with size 0 or >1 was deprecated as of 1.1.0. Please use reframe() for this instead.

Details

This function is experimental, and is subject to change in the future.

The way in which the measured variables are aggregated is specified in a similar way to how ⁠[dplyr::summarise()]⁠ is used.

See Also

reconcile(), is_aggregated()

Examples

library(tsibble)
tourism %>% 
  aggregate_key(Purpose * (State / Region), Trips = sum(Trips))


fabletools documentation built on Oct. 12, 2023, 1:07 a.m.