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

partition_index {tibbletime} | R 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 = "yearly", 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'` / `'1 yearly'` / `'yearly'` 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'))

[Package tibbletime version 0.1.6 Index]