Exercise

Practice rounding

As you saw in the video, round_date() rounds a date to the nearest value, floor_date() rounds down, and ceiling_date() rounds up.

All three take a unit argument which specifies the resolution of rounding. You can specify "second", "minute", "hour", "day", "week", "month", "bimonth", "quarter", "halfyear", or "year". Or, you can specify any multiple of those units, e.g. "5 years", "3 minutes" etc.

Try them out with the release datetime of R 3.4.1.

Instructions

100 XP
  • Choose the right function and units to round r_3_4_1 down to the nearest day.
  • Choose the right function and units to round r_3_4_1 to the nearest 5 minutes.
  • Choose the right function and units to round r_3_4_1 up to the nearest week.
  • Find the time elapsed on the day of release at the time of release by subtracting r_3_4_1 rounded down to the day from r_3_4_1.