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

View Course

Exercise instructions

  • Import the daily data, "akl_weather_daily.csv" with read_csv().
  • Print akl_daily_raw to confirm the date column hasn't been interpreted as a date. Can you see why?
  • Using mutate() overwrite the column date with a parsed version of date. You need to specify the parsing function. Hint: the first date should be September 1.
  • Print akl_daily to verify the date column is now a Date.
  • Take a look at the data by plotting date on the x-axis and max_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()