Count values ​​based on criteria

I have a data frame, of which one column contains data on time ( YYYY-MM-DD hh:mm:ss), and the other contains indicators of staff availability (number of employees available at a specific time).

I want to calculate the number of employees available, where it hourmatches (between 00-23) and the value minuteis between 00 - 59.

Consider this example data frame ( df):

TIME                   STAFF_AVAIL
2018-01-01 06:58:53    05
2018-01-01 07:00:00    10
2018-01-01 07:04:45    20
2018-01-01 07:04:55    25
2018-01-01 07:21:00    20
2018-01-01 07:58:04    18
2018-01-01 07:59:59    12
2018-01-01 08:00:00    17
2018-01-01 08:01:04    30

I want to count the number of employees available for each hour, up to one second (inclusive) until the next hour.

Using dfas an example, I want to calculate the number of employees available if the hour is equal 7and where the corresponding minutes are between 00- 59(inclusive).

, 7:00:00 08:00:00, 105 (10 + 20 + 25 + 20 + 18 + 12).

?

-2
1

lubridate plus dplyr:

library(lubridate);
library(dplyr);
df %>%
    mutate(
        TIME = ymd_hms(TIME),
        TIME.hr.bin = floor_date(TIME, unit = "hour")) %>%
    group_by(TIME.hr.bin) %>%
    summarise(n = sum(STAFF_AVAIL));
#  TIME.hr.bin             n
#  <dttm>              <int>
#1 2018-01-01 06:00:00     5
#2 2018-01-01 07:00:00   105
#3 2018-01-01 08:00:00    47

df <- read.table(text =
    "TIME                   STAFF_AVAIL
'2018-01-01 06:58:53'    05
'2018-01-01 07:00:00'    10
'2018-01-01 07:04:45'    20
'2018-01-01 07:04:55'    25
'2018-01-01 07:21:00'    20
'2018-01-01 07:58:04'    18
'2018-01-01 07:59:59'    12
'2018-01-01 08:00:00'    17
'2018-01-01 08:01:04'    30", header = T)
0

All Articles