LoslegenKostenlos loslegen

Examining intervals. Reigns of kings and queens

You can create an interval by using the operator %--% with two datetimes. For example ymd("2001-01-01") %--% ymd("2001-12-31") creates an interval for the year of 2001.

Once you have an interval you can find out certain properties like its start, end and length with int_start(), int_end() and int_length() respectively.

Practice by exploring the reigns of kings and queens of Britain (and its historical dominions).

Diese Übung ist Teil des Kurses

Working with Dates and Times in R

Kurs anzeigen

Anleitung zur Übung

We've put the data monarchs in your workspace.

  • Print monarchs to take a look at the data
  • Create a new column called reign that is an interval between from and to.
  • Create another new column, length, that is the interval length of reign. The rest of the pipeline we've filled in for you, it arranges by decreasing length and selects the name, length and dominion columns.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Print monarchs
 

# Create an interval for reign
monarchs <- monarchs %>%
  mutate(___ = ___ %--% ___) 

# Find the length of reign, and arrange
monarchs %>%
  mutate(length = ___) %>% 
  arrange(desc(length)) %>%
  select(name, length, dominion)
Code bearbeiten und ausführen