Import hourly weather data
The hourly data is a little different. The date information is spread over three columns year, month and mday, so you'll need to use make_date() to combine them.
Then the time information is in a separate column again, time. It's quite common to find date and time split across different variables. One way to construct the datetimes is to paste the date and time together and then parse them. You'll do that in this exercise.
Deze oefening maakt deel uit van de cursus
Working with Dates and Times in R
Oefeninstructies
- Import the hourly data,
"akl_weather_hourly_2016.csv"withread_csv(), then printakl_hourly_rawto confirm the date is spread overyear,monthandmday. - Using
mutate()create the columndatewith usingmake_date(). - We've pasted together the
dateandtimecolumns. Createdatetimeby parsing thedatetime_stringcolumn. - Take a look at the
date,timeanddatetimecolumns to verify they match up. - Take a look at the data by plotting
datetimeon the x-axis andtemperatureof the y-axis.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
library(lubridate)
library(readr)
library(dplyr)
library(ggplot2)
# Import "akl_weather_hourly_2016.csv"
akl_hourly_raw <- ___
# Print akl_hourly_raw
___
# Use make_date() to combine year, month and mday
akl_hourly <- akl_hourly_raw %>%
mutate(date = make_date(year = ___, month = ___, day = ___))
# Parse datetime_string
akl_hourly <- akl_hourly %>%
mutate(
datetime_string = paste(date, time, sep = "T"),
datetime = ___(datetime_string)
)
# Print date, time and datetime columns of akl_hourly
akl_hourly %>% select(___, ___, ___)
# Plot to check work
ggplot(akl_hourly, aes(x = ___, y = ___)) +
geom_line()