Here you go
library(dplyr)
library(hms)
test <- data.frame(
stringsAsFactors = FALSE,
patient_id = c("f3088f25feefc6e0","a27900c96b5b5ded","75848116245f12d7",
"bfbd0a335f50af7f","5b8bd4f78e963c52",
"d46a94cabebf47f1"),
case_date = c("2019-04-23",
"2017-01-26","2013-01-17","2019-05-18",
"2019-05-18","2019-06-01"),
final_primary_assessment = c("Short of Breath","Fracture/s","Arrhythmia",
"Airway Obstruction","Crush Injury","Vomiting"),
scene_duration_time = c("2940s (~49 minutes)","660s (~11 minutes)",
"900s (~15 minutes)","1320s (~22 minutes)","2580s (~43 minutes)",
"6480s (~1.8 hours)"),
transport_duration_time = c(NA, NA, NA, NA, NA, NA),
cardiac_arrest_indicator = c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE),
unit_vehicle_type = c("Ambulance",
"Ambulance","Ambulance","Ambulance","Ambulance",
"Ambulance"),
call_received_time = c("20:07",
"15:55","20:35","14:08","17:57","20:56"),
LST = c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE),
Year = c(2019, 2017, 2013, 2019, 2019, 2019),
skill_set = as.factor(c("ICP","ICP","ICP","Paramedic",
"ICP","ICP")),
highest_dispatch_code = as.factor(c("2", "2", "1", "1", "1", "2")),
highest_transport_code = as.factor(c("2", "2", "3", "1", "2", "2"))
)
test %>%
mutate(call_received_time = as_hms(paste0(call_received_time, ":00")),
shift_id = if_else(call_received_time >= as_hms("08:00:00") & call_received_time < as_hms("18:00:00"),
"Day",
"Nigth"))
#> patient_id case_date final_primary_assessment scene_duration_time
#> 1 f3088f25feefc6e0 2019-04-23 Short of Breath 2940s (~49 minutes)
#> 2 a27900c96b5b5ded 2017-01-26 Fracture/s 660s (~11 minutes)
#> 3 75848116245f12d7 2013-01-17 Arrhythmia 900s (~15 minutes)
#> 4 bfbd0a335f50af7f 2019-05-18 Airway Obstruction 1320s (~22 minutes)
#> 5 5b8bd4f78e963c52 2019-05-18 Crush Injury 2580s (~43 minutes)
#> 6 d46a94cabebf47f1 2019-06-01 Vomiting 6480s (~1.8 hours)
#> transport_duration_time cardiac_arrest_indicator unit_vehicle_type
#> 1 NA FALSE Ambulance
#> 2 NA FALSE Ambulance
#> 3 NA FALSE Ambulance
#> 4 NA FALSE Ambulance
#> 5 NA FALSE Ambulance
#> 6 NA FALSE Ambulance
#> call_received_time LST Year skill_set highest_dispatch_code
#> 1 20:07:00 FALSE 2019 ICP 2
#> 2 15:55:00 FALSE 2017 ICP 2
#> 3 20:35:00 FALSE 2013 ICP 1
#> 4 14:08:00 TRUE 2019 Paramedic 1
#> 5 17:57:00 FALSE 2019 ICP 1
#> 6 20:56:00 FALSE 2019 ICP 2
#> highest_transport_code shift_id
#> 1 2 Nigth
#> 2 2 Day
#> 3 3 Nigth
#> 4 1 Day
#> 5 2 Day
#> 6 2 Nigth
Created on 2022-07-09 by the reprex package (v2.0.1)