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 ejercicio forma parte del curso
Working with Dates and Times in R
Instrucciones del ejercicio
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 betweenfrom
andto
. - Create another new column,
length
, that is the interval length ofreign
. The rest of the pipeline we've filled in for you, it arranges by decreasinglength
and selects thename
,length
anddominion
columns.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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)