I have a large data set containing time in hh:mm:ss format and I would like to convert these to a decimal format while ignoring the hours (hh). I have used strptime but this does not seem to convert it.
To be more precise I would like to change 00:01:38
into 1,6333
and 01:18:30
into 78,5
.
How do I do this in R?
There is probably a lubridate function for this, but I'd do it like this:
Ignoring the hours:
It's relatively trivial to write a function which does the conversion for you. Assuming your input is character vectors:
You can use
stringsplit
andsapply
Result:
Credits go to @Joris Meys
Just extended his example: How to convert time (mm:ss) to decimal form in R