Timezones in the weather data
Did you ever notice that in the hourly Auckland weather data there was another datetime column, date_utc
? Take a look:
tibble::glimpse(akl_hourly)
The datetime
column you created represented local time in Auckland, NZ. I suspect this additional column, date_utc
represents the observation time in UTC (the name seems a big clue). But does it really?
Use your new timezone skills to find out.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
The data is available in the akl_hourly
data frame.
- What timezone are
datetime
anddate_utc
currently in? Examine the head of thedatetime
anddate_utc
columns to find out. - Fix
datetime
to have the timezone for"Pacific/Auckland"
. - Reexamine the head of the
datetime
column to check the times have the same clocktime, but are now in the right timezone. - Now tabulate up the difference between the
datetime
anddate_utc
columns. It should be zero if our hypothesis was correct.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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(___ - ___)