Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert hours and minuets into minuets in R

I have a vector of event times in the form of hours, minuets and seconds but i now wish to convert these all to minuets, for example 01:02:18 would become 62.

my data

times
"01:02:18" "01:47:37" "01:18:48" "01:32:54" "01:09:41" "01:50:30"

code tried with no joy

time = format(strptime(matchtime,"%H:%M:%S"),'%M')

Guess something could be done by adding the hours and minuets but unsure on how to do this too

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If we want to extract the minutes and hours

library(lubridate)
v1 <- hms(times)
v1@hour * 60 + v1@minute
[1]  62 107  78  92  69 110

Or to include the seconds as well

period_to_seconds(hms(times))/60
[1]  62.30000 107.61667  78.80000  92.90000  69.68333 110.50000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading