View source: R/partition_index.R
partition_index | R Documentation |
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.
partition_index(index, period = "year", start_date = NULL, ...)
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 Note that you can pass the specification in a flexible way:
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. |
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.
as_period()
, collapse_index()
data(FB) partition_index(FB$date, '2 year') dplyr::mutate(FB, partition_index = partition_index(date, '2 day'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.