ПочатиПочніть безкоштовно

Times without dates

For this entire course, if you've ever had a time, it's always had an accompanying date, i.e. a datetime. But sometimes you just have a time without a date.

If you find yourself in this situation, the hms package provides an hms class of object for holding times without dates, and the best place to start would be with as.hms().

In fact, you've already seen an object of the hms class, but I didn't point it out to you. Take a look in this exercise.

Ця вправа є частиною курсу

Working with Dates and Times in R

Переглянути курс

Інструкції до вправи

  • Use read_csv() to read in "akl_weather_hourly_2016.csv". readr knows about the hms class, so if it comes across something that looks like a time it will use it.
  • In this case the time column has been parsed as a time without a date. Take a look at the structure of the time column to verify it has the class hms.
  • hms objects print like times should. Take a look by examining the head of the time column.
  • You can use hms objects in plots too. Create a plot with time on the x-axis, temperature on the y-axis, with lines grouped by date.

Інтерактивна практична вправа

Спробуйте виконати цю вправу, доповнивши цей зразок коду.

# Import auckland hourly data 
akl_hourly <- read_csv(___)

# Examine structure of time column
str(___)

# Examine head of time column
head(___)

# A plot using just time
ggplot(akl_hourly, aes(x = ___, y = ___)) +
  geom_line(aes(group = make_date(year, month, mday)), alpha = 0.2)
Редагувати та запускати код