I try to round dates (POSIXlt object) to the nearest 5 minutes. I tried to use round_date() function and run into following situation:
> date
[1] "2012-11-01 15:41:00 EET"
> is.POSIXlt(date)
[1] TRUE
> round_date(date, "hour")
[1] "2012-11-01 16:00:00 EET"
> round_date(date, "min")
[1] "2012-11-01 15:41:00 EET"
> round_date(date, "5 mins")
Error in above - mid : non-numeric argument to binary operator
It seems to work for second, minute, hour and day. All the other units listed in the examples return this error.
I followed the advice from this thread and specified tz, but this didn't change anything.
period() function seems to work fine:
> period("5 mins")
[1] "5M 0S"
The above example is for the sake of simplicity as this data is a part of data frame. I don't know if that is relevant, but I also tried to work around it using mutate and replace. That failed with
x 'origin' must be supplied
Thanks!
EDIT
The problem was reproducible for POSIXlt objects. Bug report is submitted. Quick fix for my problem was:
> round_date(as.POSIXct(date), "5 mins")
[1] "2012-11-01 15:40:00 EET"