Import daily weather data
In practice you won't be parsing isolated dates and times, they'll be part of a larger dataset. Throughout the chapter after you've mastered a skill with a simpler example (the release times of R for example), you'll practice your lubridate
skills in context by working with weather data from Auckland NZ.
There are two data sets: akl_weather_daily.csv
a set of once daily summaries for 10 years, and akl_weather_hourly_2016.csv
observations every half hour for 2016. You'll import the daily data in this exercise and the hourly weather in the next exercise.
You'll be using functions from dplyr
, so if you are feeling rusty, you might want to review filter()
, select()
and mutate()
.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
- Import the daily data,
"akl_weather_daily.csv"
withread_csv()
. - Print
akl_daily_raw
to confirm thedate
column hasn't been interpreted as a date. Can you see why? - Using
mutate()
overwrite the columndate
with a parsed version ofdate
. You need to specify the parsing function. Hint: the first date should be September 1. - Print
akl_daily
to verify thedate
column is now aDate
. - Take a look at the data by plotting
date
on the x-axis andmax_temp
of the y-axis.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(lubridate)
library(readr)
library(dplyr)
library(ggplot2)
# Import CSV with read_csv()
akl_daily_raw <- read_csv(___)
# Print akl_daily_raw
___
# Parse date
akl_daily <- akl_daily_raw %>%
mutate(date = ___(date))
# Print akl_daily
___
# Plot to check work
ggplot(akl_daily, aes(x = ___, y = ___)) +
geom_line()