floor_index: A simple wrapper of 'lubridate::floor_date()'

View source: R/round-index.R

floor_indexR Documentation

A simple wrapper of lubridate::floor_date()

Description

This is a thin wrapper around a lubridate::floor_date() that works for hms, yearmon, and yearqtr classes as well.

Usage

floor_index(x, unit = "seconds")

Arguments

x

a vector of date-time objects

unit

a string, Period object or a date-time object. When a singleton string, it specifies a time unit or a multiple of a unit to be rounded to. Valid base units are second, minute, hour, day, week, month, bimonth, quarter, season, halfyear and year. Arbitrary unique English abbreviations as in the period() constructor are allowed. Rounding to multiples of units (except weeks) is supported. When unit is a Period object, units of the period objects are used. This is equivalent to converting the period object to its string representation and passing as unit argument.

When unit is a date-time object rounding is done to the nearest of the elements in unit. If range of unit vector does not cover the range of x ceiling_date() and floor_date() round to the max(x) and min(x) for elements that fall outside of range(unit).

See Also

lubridate::floor_date()

Examples


data(FB)
dplyr::mutate(FB, date2 = floor_index(date, "year"))

time_test <- create_series('00:00:00'~'12:00:00',
                           '1 minute', class = "hms")

dplyr::mutate(time_test, date2 = floor_index(date, "hour"))


business-science/tibbletime documentation built on Jan. 28, 2023, 10:34 a.m.