In R convert a list of numbers that represent time in hours to a POSIXct or Date variable format

Viewed 36

I have a list of times that are an output of a model, these are in a decimal number format and represent the time from the start of the model running in hours, but they have not been given any units in the output, they are just numbers.

What I would like to do is convert these numbers into a date stamp format, using the numbers as hours the model has run. Specifically as either a POSIXct or Date variable so I can start use the Bupar library.

So for example I would like to convert 1.75, into 1 hour 45 minutes and 25.5 into a time that would equal 1 day 1 hour and 30 mins.

Thanks for any help

1 Answers

One possible way:

We could use seconds_to_period() function from lubridate after multiplying by 3600 to get seconds:

library(lubridate)
x <- 1.75
seconds_to_period(x*3600)
#[1] "1H 45M 0S"
Related