ComeçarComece de graça

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).

Este exercício faz parte do curso

Working with Dates and Times in R

Ver curso

Instruções do exercício

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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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)
Editar e executar o código