partition_index: Partition an index vector into an integer vector representing...

View source: R/partition_index.R

partition_indexR Documentation

Partition an index vector into an integer vector representing groups

Description

partition_index() takes an index vector and returns an integer vector that can be used for grouping by periods. This is the workhorse for many other tibbletime functions.

Usage

partition_index(index, period = "year", start_date = NULL, ...)

Arguments

index

A vector of date indices to create groups for.

period

A character specification used for time-based grouping. The general format to use is "frequency period" where frequency is a number like 1 or 2, and period is an interval like weekly or yearly. There must be a space between the two.

Note that you can pass the specification in a flexible way:

  • 1 Year: '1 year' / '1 Y'

This shorthand is available for year, quarter, month, day, hour, minute, second, millisecond and microsecond periodicities.

Additionally, you have the option of passing in a vector of dates to use as custom and more flexible boundaries.

start_date

Optional argument used to specify the start date for the first group. The default is to start at the closest period boundary below the minimum date in the supplied index.

...

Not currently used.

Details

This function is used internally, but may provide the user extra flexibility in some cases.

Grouping can only be done on the minimum periodicity of the index and above. This means that a daily series cannot be grouped by minute. An hourly series cannot be grouped by 5 seconds, and so on. If the user attempts this, an error will be thrown.

See Also

as_period(), collapse_index()

Examples


data(FB)

partition_index(FB$date, '2 year')

dplyr::mutate(FB, partition_index = partition_index(date, '2 day'))


tibbletime documentation built on Feb. 16, 2023, 7:09 p.m.