1. Learn
  2. /
  3. Courses
  4. /
  5. Working with Dates and Times in R

Exercise

Rounding with the weather data

When is rounding useful? In a lot of the same situations extracting date components is useful. The advantage of rounding over extracting is that it maintains the context of the unit. For example, extracting the hour gives you the hour the datetime occurred, but you lose the day that hour occurred on (unless you extract that too), on the other hand, rounding to the nearest hour maintains the day, month and year.

As an example you'll explore how many observations per hour there really are in the hourly Auckland weather data.

Instructions

100 XP
  • Create a new column called day_hour that is datetime rounded down to the nearest hour.
  • Use count() on day_hour to count how many observations there are in each hour. What looks like the most common value?
  • Extend the pipeline, so that after counting, you filter for observations where n is not equal to 2.