Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Character (HH:MM) to Minutes

Tags:

time

r

character

I've spent a few hours reading various packages documentation, but am still stumped (coming back to using R after a few years away).

I have time data of class character in my data frame e.g. 03:30

How can I convert this to minutes ? i.e. 03:30 goes to 210

Any ideas?

Many thanks indeed.

like image 967
Ash Avatar asked Oct 20 '25 02:10

Ash


1 Answers

One option would be

library(lubridate)
as.numeric(hm(str1)) /60
#[1] 210

Or specifically convert to seconds with period_to_seconds and divide by 60

period_to_seconds(hm(str1))/60
#[1] 210

data

str1 <- "03:30"
like image 60
akrun Avatar answered Oct 22 '25 16:10

akrun