如何在R中将小时内的excel内部编码转换为小时? [英] how to convert excel internal coding for hours to hours in R?
本文介绍了如何在R中将小时内的excel内部编码转换为小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
推荐答案
您可以使用hms
:
library(hms)
hms(days = 0.4305556)
#> 10:20:00.00384
减去两个hms
对象以返回一个时差以秒为单位的difftime
对象:
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
或者使用difftime
函数来获取不同单位的时差:
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
这篇关于如何在R中将小时内的excel内部编码转换为小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文