我有时间从文件导入。该列被视为数字,如下所示:
head(RawData$TimeStart, 10)
[1] 0.00 0.00 0.00 30.19 0.00 25.00 0.00 9.20 0.00 0.00
此数据表示在0.0分钟和30分钟,19秒(30.19)处拍摄的样本。
我希望此列现在转换为以下格式:
> head(RawData$Converted, 10)
[1] "2017-07-05 00:00:00 AEST" "2017-07-05 00:00:00 AEST" "2017-07-05 00:00:00 AEST" "2017-07-05 00:30:19 AEST"
[5] "2017-07-05 00:00:00 AEST" "2017-07-05 00:25:00 AEST" "2017-07-05 00:00:00 AEST" "2017-07-05 00:09:20 AEST"
[9] "2017-07-05 00:00:00 AEST" "2017-07-05 00:00:00 AEST"
我尝试过以下方法:
RawData$Converted <- as.POSIXct(RawData$TimeStart, origin='1970-01-01', tz='Australia/Darwin')
但这并没有给出今天的日期/时间。我很困惑,所以任何帮助都会非常感激。
答案 0 :(得分:3)
打破您的数值,将它们全部转换为秒,然后将其添加到今天的日期时间:
x <- c(0.00,0.00,0.00,30.19,0.00,25.00,0.00,9.20,0.00,0.00)
as.POSIXct(format(Sys.Date()), tz="Australia/Darwin") + (floor(x)*60) + ((x-floor(x))*100)
# [1] "2017-07-05 00:00:00 ACST" "2017-07-05 00:00:00 ACST" "2017-07-05 00:00:00 ACST" "2017-07-05 00:30:19 ACST"
# [5] "2017-07-05 00:00:00 ACST" "2017-07-05 00:25:00 ACST" "2017-07-05 00:00:00 ACST" "2017-07-05 00:09:20 ACST"
# [9] "2017-07-05 00:00:00 ACST" "2017-07-05 00:00:00 ACST"
这是在达尔文时间ACST
而不是AEST
,但我认为这就是你想要的。