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.
This exercise is part of the course
Working with Dates and Times in R
Exercise instructions
- Use
read_csv()to read in"akl_weather_hourly_2016.csv".readrknows about thehmsclass, so if it comes across something that looks like a time it will use it. - In this case the
timecolumn has been parsed as a time without a date. Take a look at the structure of thetimecolumn to verify it has the classhms. hmsobjects print like times should. Take a look by examining the head of thetimecolumn.- You can use
hmsobjects in plots too. Create a plot withtimeon the x-axis,temperatureon the y-axis, with lines grouped bydate.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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)