Exercise

What can you extract?

As you saw in the video, components of a datetime can be extracted by lubridate functions with the same name like year(), month(), day(), hour(), minute() and second(). They all work the same way just pass in a datetime or vector of datetimes.

There are also a few useful functions that return other aspects of a datetime like if it occurs in the morning am(), during daylight savings dst(), in a leap_year(), or which quarter() or semester() it occurs in.

Try them out by exploring the release times of R versions using the data from Chapter 1.

Instructions

100 XP

We've put release_time, the datetime column of the releases dataset from Chapter 1, in your workspace.

  • Examine the head() of release_time to verify this is a vector of datetimes.
  • Extract the month from release_time and examine the first few with head().
  • To see which months have most releases, extract the month then pipe to table().
  • Repeat, to see which years have the most releases.
  • Do releases happen in the morning (UTC)? Find out if the hour of a release is less than 12 and summarise with mean().
  • Alternatively use am() to find out how often releases happen in the morning.