[Experimental]

aggregate_index(.data, .window, ..., .offset = "end", .bin_size = NULL)

Arguments

.data

A tsibble.

.window

Temporal aggregations to include. The default (NULL) will automatically identify appropriate temporal aggregations. This can be specified in several ways (see details).

...

<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.

.offset

Offset the temporal aggregation windows to align with the start or end of the data. If FALSE, no offset will be applied (giving common breakpoints for temporal bins.)

.bin_size

Temporary. Define the number of observations in each temporal bucket

Details

This feature is very experimental. It currently allows for temporal aggregation of daily data as a proof of concept.

The aggregation .window can be specified in several ways:

  • A character string, containing one of "day", "week", "month", "quarter" or "year". This can optionally be preceded by a (positive or negative) integer and a space, or followed by "s".

  • A number, taken to be in days.

  • A difftime object.

Examples

library(tsibble)
pedestrian %>%
  # Currently only supports daily data
  index_by(Date) %>% 
  dplyr::summarise(Count = sum(Count)) %>% 
  # Compute weekly aggregates
  fabletools:::aggregate_index("1 week", Count = sum(Count))
#> # A tsibble: 104 x 2 [7D]
#>    Date        Count
#>    <date>      <int>
#>  1 2015-01-03 182896
#>  2 2015-01-10 231513
#>  3 2015-01-17 348879
#>  4 2015-01-24 313666
#>  5 2015-01-31 238603
#>  6 2015-02-07 219104
#>  7 2015-02-14 377340
#>  8 2015-02-21 530409
#>  9 2015-02-28 444666
#> 10 2015-03-07 614122
#> # ℹ 94 more rows