I need to convert time intervals in the format %H:%M:%S (class = factor) to class = difftime. I am currently using as.difftime() to do this, but it returns NA when the hour value is > 23.
TimeElapsed_raw = as.factor(c("03:59:59", "21:00:00", "01:03:46", "44:00:00", "24:59:59"))
TimeElapsed = as.difftime(as.character(TimeElapsed_raw), format = "%H:%M:%S")
TimeElapsed
Time differences in hours
[1] 3.999722 21.000000 1.062778 NA NA
I have the same problem whether or not I include the format statement in as.difftime():
as.difftime("65:01:17")
Time difference of NA secs
But this works:
as.difftime(65.1, units = "hours")
Time difference of 65.1 hours
I've also tried using the lubridate as.duration() function, but the values it calculates seem nonsensical.
as.duration(TimeElapsed_raw)
[1] "2s" "3s" "1s" "5s" "4s"
Any help would be appreciated!