Convert time from numeric to time format in R

You can use as.POSIXct after having multiplied your number by the number of seconds in a day (60 * 60 * 24)

nTime <- c(0.3840277777777778, 0.3847222222222222, 0.3854166666666667)
format(as.POSIXct((nTime) * 86400, origin = "1970-01-01", tz = "UTC"), "%H:%M")
## [1] "09:13" "09:14" "09:15"

For people who want the opposite way: given the 09:13:00, get 0.3840278

as.numeric(chron::times("09:13:00"))

Essentially, the idea is that one whole day is 1,so noon (12pm) is 0.5.


Another option is times from chron

library(chron)
times(nTime)
#[1] 09:13:00 09:14:00 09:15:00

To strip off the seconds,

substr(times(nTime),1,5)
#[1] "09:13" "09:14" "09:15"

data

nTime <- c(0.3840277777777778, 0.3847222222222222, 0.3854166666666667)