问题
I have a hour variable stored as excel internal coding in R. See (https://www.ablebits.com/office-addins-blog/2015/06/23/excel-time-format-now-time-functions/), for example 0.4305556 is equivalent to 10:20:00 AM. How to convert 0.4305556 to 10:20:00 AM in R. After this i need to substract times to find time diferennces.
回答1:
You can use hms
:
library(hms)
hms(days = 0.4305556)
#> 10:20:00.00384
Subtract two hms
objects to return a difftime
object with the time difference in seconds:
hms(days = 0.5) - hms(days = 0.25)
#> Time difference of 21600 secs
Or to get the time difference in a different unit use the difftime
function:
difftime(hms(days = 0.5), hms(days = 0.25), units = "hours")
#> Time difference of 6 hours
来源:https://stackoverflow.com/questions/57482012/how-to-convert-excel-internal-coding-for-hours-to-hours-in-r