time_floor: Floor a 'tbl_time' object

Description Usage Arguments Details Examples

View source: R/time_floor.R

Description

This is essentially a convenient wrapper to [lubridate::floor_date()] that allows flooring of a 'tbl_time' object using a period formula.

Usage

1
time_floor(x, period, ...)

Arguments

x

A 'tbl_time' object.

period

A formula or character specification used for time-based grouping.

If a formula, e.g. '1~year', the formula is split and parsed to form the grouping period. The 'period' argument accepts a formula of the form 'multiple ~ period' allowing for flexible period grouping. The following are examples:

* 1 Year: '1~y' * 3 Months: '3~m' * 90 Days: '90~d'

Note that while shorthand is used above, an attempt is made to recognize more explicit period names such as:

* 2 Year: '2~year' / '2~years' / '2~yearly'

The 'period' argument also accepts characters that are converted to their corresponding periods. The following are accepted:

* '"yearly"' or '"y"' * '"quarterly"' or '"q"' * '"monthly"' or '"m"' * '"weekly"' or '"w"' * '"daily"' or '"d"' * '"hour"' or '"h"' * '"minute"' or '"M"' * '"second"' or '"s"'

...

Arguments passed on to [lubridate::floor_date()]

Details

This function respects [dplyr::group_by()] groups.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
example_series <- create_series(~2013, 2~day)

# When you convert to a period, the lowest available date in that period
# is chosen
example_series %>%
  as_period(1~m)

# Sometimes you want to additionally floor that date so that all dates
# are consistent
example_series %>%
  as_period(1~m) %>%
  time_floor(1~m)

DavisVaughan/tibbletime3 documentation built on Nov. 23, 2017, 5:30 p.m.