1

in can r I have a numeric vector like c(15, 270, 540, 30, 15, 1440) representing minutes - but how can I create a vector out of this displaying hours and minutes?

Thanks in advance Jasmin

Thomas
  • 43,637
  • 12
  • 109
  • 140
Jasmin
  • 11
  • 3
  • 2
    Try with `library(lubridate);seconds_to_period(v1*60)` Related post [here](https://stackoverflow.com/questions/27312292/convert-seconds-to-days-hoursminutesseconds) – akrun Dec 11 '17 at 17:00

1 Answers1

1

This uses no packages and gives hours and minutes as asked (as opposed to days, hours and minutes).

x <- c(15, 270, 540, 30, 15, 1440)

sprintf("%02d:%02d", x %/% 60, x %% 60)
## [1] "00:15" "04:30" "09:00" "00:30" "00:15" "24:00"
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341