In the lubridate
package there is a function hms()
that returns a time object:
library(lubridate)
x <- c("118:34:42", "114:12:12")
tt <- hms(x)
tt
[1] 118 hours, 34 minutes and 42 seconds
[2] 114 hours, 12 minutes and 12 seconds
The function hms()
returns an object of class Period
:
str(tt)
Formal class 'Period' [package "lubridate"] with 6 slots
..@ .Data : num [1:2] 42 12
..@ year : num [1:2] 0 0
..@ month : num [1:2] 0 0
..@ day : num [1:2] 0 0
..@ hour : num [1:2] 118 114
..@ minute: num [1:2] 34 12
You can do arithmetic using these objects. For example:
tt[2] - tt[1]
[1] -4 hours, -22 minutes and -30 seconds