Convert Character (HH:MM) to Minutes

Viewed 484

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.

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"
Related