为什么strftime的改变我的次R'
问题描述:
我在含有时间柱上用24小时时钟一个数据帧:为什么strftime的改变我的次R'
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)
阅读的人我想它的一个时区的问题,但我仍然不知道如何解决这个问题。 – 5r9n
设置使用''strftime' – SymbolixAU
我怎么设置时区,使之不会改变任何东西的tz'参数的时区? – 5r9n