Exercise

Extracting for filtering and summarizing

Another reason to extract components is to help with filtering observations or creating summaries. For example, if you are only interested in observations made on weekdays (i.e. not on weekends) you could extract the weekdays then filter out weekends, e.g. wday(date) %in% 2:6.

In the last exercise you saw that January, February and March were great times to visit Auckland for warm temperatures, but will you need a raincoat?

In this exercise you'll find out! You'll use the hourly data to calculate how many days in each month there was any rain during the day.

Instructions

100 XP
  • Create new columns for the hour and month of the observation from datetime. Make sure you label the month.
  • Filter to just daytime observations, where the hour is greater than or equal to 8 and less than or equal to 22.
  • Group the observations first by month, then by date, and summarise by using any() on the rainy column. This results in one value per day
  • Summarise again by summing any_rain. This results in one value per month