Convert char to hour

2

I need to convert a field from a char file to something that is averagely calculable.

This is a field that refers to hours originally.

system.time(cpc_call<-fread("ACIONAMENTO_CALL.csv",header = T , sep= ";")) # Importa tabela

When I see the imported file it appears as chr.

Then in the attempt to convert, I made the code below:

cpc_call$Tempo_Falado = as.numeric(cpc_call$Tempo_Falado) # Transforma tempo falado em tempo

cpc_call %>%
group_by(Outcome) %>%
summarise(median(cpc_call$Tempo_Falado))

But the result of the column referring to the average returns only "NA"

Edit: Follow the output with: dput (head (cpc_call $ Time_Dial, 20))

> dput(head(cpc_call$Tempo_Falado, 20))
c("00:01:20", "00:01:46", "00:01:36", "00:05:26", "00:01:37", 
"00:05:11", "00:02:34", "00:01:32", "00:01:44", "00:02:51", "00:02:45", 
"00:01:45", "00:02:22", "00:02:04", "00:03:17", "00:01:59", "00:01:44", 
"00:01:31", "00:01:23", "00:01:43")
    
asked by anonymous 15.12.2017 / 21:25

1 answer

1

Using the chron package you can transform your character vector into type times , which will allow you to perform operations such as average, median. >

cpc_call <- c("00:01:20", "00:01:46", "00:01:36", "00:05:26", "00:01:37", 
"00:05:11", "00:02:34", "00:01:32", "00:01:44", "00:02:51", "00:02:45", 
"00:01:45", "00:02:22", "00:02:04", "00:03:17", "00:01:59", "00:01:44", 
"00:01:31", "00:01:23", "00:01:43")
library(chron)
cpc_call <- chron(times = cpc_call)

With these values, the average value was

mean(cpc_call)
[1] 00:02:18

And doing the conference (in seconds),

mean(60*minutes(cpc_call) + seconds(cpc_call))
[1] 138.5
    
18.12.2017 / 18:56