I have a variable in the form of minutes spent in an activity. I would like to convert this number into hours and minutes by taking the digits into account but without producing seconds. Here's an example:
minutes<-c(81.4398, 50.9903,107.5511,433.3051,10.1234)
minutes
I would like the outcome in a clock format:
hrsmins<- c(1:21,0:51,1:48,7:13,0:10)
Note that the outcome, does not show the clock time of the day but hours and minutes in the activity. I have a very large data set (millions of episodes). So, I would appreciate if someone can offer an efficient way of doing this conversion.
We can try with chron
library(chron)
substr(times((minutes%/%60 + minutes%%60 /60)/24), 1, 5)
#[1] "01:21" "00:50" "01:47" "07:13" "00:10"
Or it could be
sub(":\\d{2}", "", times((minutes%/%60 + minutes%%60 /3600)/24))
#[1] "01:21" "00:51" "01:48" "07:13" "00:10"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With