You can find the hms useful to handle time values
Something like
library(hms)
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# build df with hms value
tab <- expand.grid(H = hms(hours = 1:10), M = hms(minutes = (0:5)*10)) %>%
transmute(time = as_hms(H + M), value = rnorm(length(time))) %>%
as_tibble()
# use hms function to work with time object
tab %>%
mutate(two_hours = trunc_hms(time, 60*60*2)) %>%
group_by(two_hours) %>%
summarise(value = sum(value))
#> # A tibble: 6 x 2
#> two_hours value
#> <time> <dbl>
#> 1 00:00 -1.31
#> 2 02:00 -3.75
#> 3 04:00 1.37
#> 4 06:00 4.53
#> 5 08:00 -0.882
#> 6 10:00 1.71
Created on 2019-11-15 by the reprex package (v0.3.0)
Otherwise, you can also extract character and then group by hours I guess