2017-05-30 68 views
1

我在含有時間柱上用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會改變我的時代?

+0

閱讀的人我想它的一個時區的問題,但我仍然不知道如何解決這個問題。 – 5r9n

+0

設置使用''strftime' – SymbolixAU

+0

我怎麼設置時區,使之不會改變任何東西的tz'參數的時區? – 5r9n

回答

3

由於時間列不包含TZ信息,UTC假設,然後strftime使用了和在轉換本地TZ之間的差別。

所以嘗試:

all_files_hobo$time <- strftime(all_files_hobo$time, format = "%H:%M", tz = "UTC") 
0

,或者嘗試

library(lubridate) 
all_files_hobo$time <-hms(all_files_hobo$time) 
相關問題