Reputation: 8404
Let's say I have a vector of characters that correspond calculated time like:
calc<-c("1:17","0:46","11:25")
and I want to convert it to numeric values of minutes like calc<-c(77,46,685)
. Is there a way to do it?
Upvotes: 2
Views: 130
Reputation: 101373
Try the following base R option using str2lang
+ gsub
> eval(str2lang(sprintf("c(%s)", toString(gsub(":", "*60+", calc)))))
[1] 77 46 685
Upvotes: 1
Reputation: 887128
We may use ms
(minutes:seconds) from lubridate
to convert to period
class and then convert the period
to seconds with period_to_seconds
lubridate)
period_to_seconds(ms(calc))
#[1] 77 46 685
Upvotes: 1