如何将小时作为浮子转换为r的12h时间戳
我有一个数据框,其中包含8.6
,9.32
,9.79
等值之类的值。这些值代表小时的小时和分数。例如,8.6小时等于08:36 AM,而9.79小时相当于09:47 AM。我正在寻找一种简单的方法,将这些浮子转换为时间戳。一种方法可能是解析浮子的分数部分,然后乘以60,以获取分钟数,然后转换为时间戳。但是,我想知道是否有人使用lubridate
将Float转换为时间戳。
df <- structure(list(start_time = c(8.6, 9.32, 9.79, 10.09, 10.63,
8.64)), row.names = c(NA, 6L), class = "data.frame")
I have a dataframe that contains values such as 8.6
, 9.32
, 9.79
, etc. These values represent hours and fractions of hours. For instance, 8.6 hours equates to 08:36am, and 9.79 hours equates to 09:47am. I'm looking for an easy way to convert these floats into a timestamp. One approach could be to parse the fractional portion of the float and multiply by 60 to get the number of minutes, then convert to a timestamp. However, I'm wondering if anyone has a better solution using something like lubridate
to convert the float to a timestamp.
df <- structure(list(start_time = c(8.6, 9.32, 9.79, 10.09, 10.63,
8.64)), row.names = c(NA, 6L), class = "data.frame")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者如果您想要Posixct DateTime:
Or if you want a POSIXct datetime: