天氣資料中的時區
你有注意到奧克蘭逐小時天氣資料裡有另一個日期時間欄位 date_utc 嗎?來看看:
tibble::glimpse(akl_hourly)
你建立的 datetime 欄位代表紐西蘭奧克蘭的當地時間。我懷疑這個額外的欄位 date_utc 代表的是 UTC 的觀測時間(欄位名稱就是個明顯的線索)。但真的是這樣嗎?
用你剛學到的時區技巧來驗證看看。
本練習屬於課程
在 R 中處理日期與時間
練習說明
資料在 akl_hourly 資料框中。
datetime和date_utc目前各是什麼時區?檢視datetime與date_utc的前幾筆資料來找答案。- 將
datetime修正為使用"Pacific/Auckland"時區。 - 再次檢視
datetime欄位的前幾筆資料,確認時鐘時間相同,但現在位於正確的時區。 - 接著彙整
datetime與date_utc欄位之間的差異。若我們的假設正確,差值應該為 0。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Examine datetime and date_utc columns
head(___)
head(___)
# Force datetime to Pacific/Auckland
akl_hourly <- akl_hourly %>%
mutate(
datetime = ___(datetime, tzone = ___))
# Reexamine datetime
head(___)
# Are datetime and date_utc the same moments
table(___ - ___)