A generic function for rounding date and time values
round_time(x, n, tz)
If POSIXct then POSIX. If date then Date.
A vector of class POSIX or Date.
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).
Time zone to be used, defaults to "UTC" (Twitter default)
## class posixct
round_time(Sys.time(), "12 hours")
## class date
unique(round_time(seq(Sys.Date(), Sys.Date() + 100, "1 day"), "weeks"))
Run the code above in your browser using DataLab