[英]Why does strftime change my times in R?
我有一个包含24小时时间列的数据帧:
canopy_understory trap_no file_name date time temp light_intensity
<chr> <int> <chr> <dttm> <time> <dbl> <dbl>
1 c 11 trap11c_160314.txt1 16-01-09 14:00:00 35.542 41
2 c 11 trap11c_160314.txt2 16-01-09 15:00:00 28.953 4
3 c 11 trap11c_160314.txt3 16-01-09 16:00:00 27.468 1
为了删除秒列,我在R中运行此代码:
all_files_hobo$time <- strftime(all_files_hobo$time, format = "%H:%M")
运行此代码后,我有以下数据帧
canopy_understory trap_no file_name date time temp light_intensity
<chr> <int> <chr> <dttm> <chr> <dbl> <dbl>
1 c 11 trap11c_160314.txt1 16-01-09 06:00 35.542 41
2 c 11 trap11c_160314.txt2 16-01-09 07:00 28.953 4
3 c 11 trap11c_160314.txt3 16-01-09 08:00 27.468 1
正如您所看到的,秒数已经消失,列已从更改为,但时间也不同。 这是有问题的。 我每次只能增加8个,但我担心这里会有一些更加阴险的事情,并且在不久的将来事情会变得混乱。 为什么strftime会改变我的时代?
由于时间列不包含TZ信息,因此假设使用UTC,然后strftime
在转换中使用它与您本地TZ之间的差异。
所以尝试:
all_files_hobo$time <- strftime(all_files_hobo$time, format = "%H:%M", tz = "UTC")
或尝试
library(lubridate)
all_files_hobo$time <-hms(all_files_hobo$time)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.