Finding the difference between two times in lubridate hms format in R

876 Views Asked by At

I have a row of times in hms format (from lubridate). For example,

begin = "12H 18M 48.58S" 
ending = "12H 21M 1.4S"

If I do ending - begin, it returns:

"3M -47.18S"

While this is correct, I would prefer the answer in seconds, so that I can use this value later as a numeric (to add to other values in the column I am hoping to build), and use in figures.

I want to find the time, in seconds, between these two times. I have tried, as.duration(ending - start), and the following error comes up:

Error in sprintf("%ds (~%s %ss)", x, x2, unit, "s)") : 
  invalid format '%d'; use format %f, %e, %g or %a for numeric objects

Any help would be much appreciated!

0

There are 0 best solutions below