If you prefer to use dplyr
, try this method:
library(hms)
library(dplyr)
c("10:01:10", "11:01:47", "12:34:56", "15:01:47", "16:01:23", "18:01:47") %>%
as_hms() %>%
as.POSIXlt() %>%
format("%H:%M") %>%
paste0(., ":00") %>%
as_hms()
Which returns:
[1] 10:01:00
[2] 11:01:00
[3] 12:34:00
[4] 15:01:00
[5] 16:01:00
[6] 18:01:00
This process simply strips the seconds
values, and replaces them with 00
values. This should achieve the outcome you're looking for.
However, if you include a date, you can use lubridate
's round_date()
function:
library(lubridate)
c("2020-08-08 10:01:10", "2020-08-08 11:01:47", "2020-08-08 12:34:56", "2020-08-08 15:01:47", "2020-08-08 16:01:23", "2020-08-08 18:01:47") %>%
ymd_hms() %>%
round_date("minute")
Which returns:
[1] "2020-08-08 10:01:00 UTC"
[2] "2020-08-08 11:02:00 UTC"
[3] "2020-08-08 12:35:00 UTC"
[4] "2020-08-08 15:02:00 UTC"
[5] "2020-08-08 16:01:00 UTC"
[6] "2020-08-08 18:02:00 UTC"