In the following data frame the ‘time’ column is character in the format hour:minute:second
id <- c(1, 2, 3, 4)
time <- c("00:00:01", "01:02:00", "09:30:01", "14:15:25")
df <- data.frame(id, time)
How can I convert ‘time’ column to a dedicated time class, so that I can perform arithmetic calculations on it?
Use the function
chronin packagechron:Do some useful things, like calculating the difference between successive elements:
chronobjects store the values internally as a fraction of seconds per day. Thus 1 second is equivalent to1/(60*60*24), or1/86400, i.e.1.157407e-05.So, to add times, one simple option is this: