I have a group of operators that their job are to call a technician if an incident ocurred with machines and repeat those contacts till the alerts are closed. I have a record of each contacts they made.
I need to look upon those data and calculate how long (in minutes) they took to call or interact.
The clock starts with the first incident alert_time and restarts/reset for each contacts made. I have created the Id, the attempt_number and the attemp_seq to control the number of contacts for each Id. However I can't calculate the minutes between each the contacts starting by the first alert.
Any body can help me find a solution?
(For instance only and with dummy data)
code:
library(tidyverse)
my_a <- data.frame(machine_id = c(12, 14, 12, 12, 14), incident_alert = c("Error_01",
"Error_02", "Error_01", "Error_01", "Error_02"), alert_time = c("2019-12-23 07:10:10",
"2019-12-23 08:01:29", "2019-12-23 07:10:10", "2019-12-23 07:10:10",
"2019-12-23 08:01:29"), operator_contact_time = c("2019-12-23 08:05:13",
"2019-12-23 08:22:10", "2019-12-23 08:35:45", "2019-12-23 09:25:52",
"2019-12-23 09:38:01"))
my_b <- my_a %>% mutate(Id = paste(machine_id, incident_alert,
alert_time, sep = "")) %>% group_by(Id) %>% mutate(attempt_numb = n(),
attemp_seq = sequence(n())) %>% select(Id, everything())
Console result:
> my_a
machine_id incident incident_time operator_contact_time
1 12 Error_01 2019-12-23 07:10:10 2019-12-23 08:05:13
2 14 Error_02 2019-12-23 08:01:29 2019-12-23 08:22:10
3 12 Error_01 2019-12-23 07:10:10 2019-12-23 08:35:45
4 12 Error_01 2019-12-23 07:10:10 2019-12-23 09:25:52
5 14 Error_02 2019-12-23 08:01:29 2019-12-23 09:38:01
> my_b
# A tibble: 5 x 7
# Groups: Id [2]
Id machine_id incident_alert alert_time operator_contac~ attempt_numb
<chr> <dbl> <fct> <fct> <fct> <int>
1 12Er~ 12 Error_01 2019-12-2~ 2019-12-23 08:0~ 3
2 14Er~ 14 Error_02 2019-12-2~ 2019-12-23 08:2~ 2
3 12Er~ 12 Error_01 2019-12-2~ 2019-12-23 08:3~ 3
4 12Er~ 12 Error_01 2019-12-2~ 2019-12-23 09:2~ 3
5 14Er~ 14 Error_02 2019-12-2~ 2019-12-23 09:3~ 2
Excel example for what I expect:
machine_id incident_alert alert_time operator_contact_time attempt_numb attemp_seq time_laps_minute
12 Error_01 2019-12-23 07:10:10 2019-12-23 08:05:13 3 1 55
14 Error_02 2019-12-23 08:01:29 2019-12-23 08:22:10 2 1 20
12 Error_01 2019-12-23 07:10:10 2019-12-23 08:35:45 3 2 30
12 Error_01 2019-12-23 07:10:10 2019-12-23 09:25:52 3 3 50
14 Error_02 2019-12-23 08:01:29 2019-12-23 09:38:01 2 2 15