Rounding time to nearest quarter hour

前端 未结 7 593
清酒与你
清酒与你 2020-12-03 13:43

I have a vector of POSIXct values and I would like to round them to the nearest quarter hour. I don\'t care about the day. How do I convert the values to hours and minutes?<

相关标签:
7条回答
  • 2020-12-03 14:12

    Old question, but would like to note that the lubridate package handles this easily now with floor_date. To cut a vector of POSIXct objects to 15 minute intervals, use like this.

    x <- lubridate::floor_date(x, "15 minutes")

    EDIT: Noted by user @user3297928, use lubridate::round_date(x, "15 minutes") for rounding to the nearest 15 minutes. The above floors it.

    0 讨论(0)
提交回复
热议问题