在R中将时间从数字格式转换为时间格式 [英] Convert time from numeric to time format in R
本文介绍了在R中将时间从数字格式转换为时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
0.3840277777777778
0.3847222222222222
0.3854166666666667
确实,他们应该是
09:12
09:13
09:13
不知道如何将它转换成正确的格式。我搜索了几个线程,所有这些都是将日期(有/没有时间)转换为正确的格式。
有人可以给我任何线索吗?
解决方案
as.POSIXct在将您的号码乘以一天中的秒数后(60 * 60 * 24)
nTime< - c(0.38402777777778,0.3847222222222222,0.3854166666666667)
格式(as.POSIXct((nTime)* 86400,origin =1970-01-01,tz =UTC),%H:%M)
## [1]09:1309:1409:15
I read data from an xls file. Apparently, the time is not in the right format. It is as follows (for example)
0.3840277777777778
0.3847222222222222
0.3854166666666667
Indeed, they should be
09:12
09:13
09:13
I don't know how to convert it to the right format. I searched several threads and all of them are about converting the date (with/without time) to the right format.
Can somebody give me any clues?
解决方案
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"
这篇关于在R中将时间从数字格式转换为时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文