BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Working with Dates and Times in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import the hourly data, "akl_weather_hourly_2016.csv" with read_csv(), then print akl_hourly_raw to confirm the date is spread over year, month and mday.
  • Using mutate() create the column date with using make_date().
  • We've pasted together the date and time columns. Create datetime by parsing the datetime_string column.
  • Take a look at the date, time and datetime columns to verify they match up.
  • Take a look at the data by plotting datetime on the x-axis and temperature of the y-axis.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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()
Kodu Düzenle ve Çalıştır