R: adding time / duration as hh: mm: ss over 24 hours

I am trying to work with temporary data regarding the duration of several experiments. This data is in the form hh: mm: ss.

exp1 <- "34:03:07" exp2 <- "00:01:10" exp3 <- "01:13:41" 

The first experiment is given as the total duration, and subsequent experiments are listed as time in excess of exp1. The final result of the time I'm looking for exp2, for example, will be 34:04:17, and for exp3 it will be 35:16:48. What is the best way to add time to exp1 when packages like chron only work in hh: mm: ss until 24:00:00?

+4
source share
1 answer

I often prefer to avoid the lengths of such Date / Time classes and simply parse the string and convert them to a numeric value in minutes.

But, as always, there is usually a package with similar functionality. In this case, lubridate has a duration class that can be useful:

 d <- new_duration(hour = 34,minute = 23,second = 23) d1 <- new_duration(hour = 12,minute = 12,second = 23) > d+d1 [1] 167746s (1.94d) 

So you can do arithmetic with them, and you can also create a duration object by passing numeric values ​​(in seconds) to as.duration .

+5
source

Source: https://habr.com/ru/post/1389342/


All Articles