round_time.Rd
A generic function for rounding date and time values
round_time(x, n, tz)
x | A vector of class POSIX or Date. |
---|---|
n | Unit to round to. Defaults to mins. Numeric values treated as seconds. Otherwise this should be one of "mins", "hours", "days", "weeks", "months", "years" (plural optional). |
tz | Time zone to be used, defaults to "UTC" (Twitter default) |
If POSIXct then POSIX. If date then Date.
## class posixct round_time(Sys.time(), "12 hours")#> [1] "2018-10-01 12:00:00 UTC"## class date unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))#> [1] "2018-09-27" "2018-10-04" "2018-10-11" "2018-10-18" "2018-10-25" #> [6] "2018-11-01" "2018-11-08" "2018-11-15" "2018-11-22" "2018-11-29" #> [11] "2018-12-06" "2018-12-13" "2018-12-20" "2018-12-27" "2019-01-03"