padr (version 0.5.0)

span_around: Span an equally spaced vector around a datetime variable

Description

Span a vector of specified interval around a variable of class Date, POSIXct, or POSIXlt..

Usage

span_around(x, interval, start_shift = NULL, end_shift = start_shift)

Arguments

x

A vector of class Date, POSIXct, or POSIXlt.

interval

Character, specifying the desired interval.

start_shift

Character, indicating the time to shift back from the first observation.

end_shift

Character, indicating the time to shift forward from the last observation.

Value

A datetime vector, with the first observation smaller or equal than min(x) and the last observation larger or equal than max(x). Spaces between points are equal to interval.

Details

Note that use of the start_shift and end_shift arguments change the entire spanning when they are not in line with the interval. It is not checked for.

Examples

Run this code
# NOT RUN {
span_around(coffee$time_stamp, "hour")
span_around(coffee$time_stamp, "hour", end_shift = "2 hour")
span_around(coffee$time_stamp, "2 day")
span_around(coffee$time_stamp, "2 day", start_shift = "2 day")
span_around(emergency$time_stamp, "week")
span_around(emergency$time_stamp, "2 month")
# }

Run the code above in your browser using DataLab