Time is of the essence
The dates when a season begins and ends can vary depending on who you ask. People in Australia will tell you that spring starts on September 1st. The Irish people in the Northern hemisphere will swear that spring starts on February 1st, with the celebration of St. Brigid's Day. Then there's also the difference between astronomical and meteorological seasons: while astronomers are used to equinoxes and solstices, meteorologists divide the year into 4 fixed seasons that are each three months long. (source: www.timeanddate.com)
A vector astro
, which contains character strings representing the dates on which the 4 astronomical seasons start, has been defined on your workspace. Similarly, a vector meteo
has already been created for you, with the meteorological beginnings of a season.
This exercise is part of the course
Intermediate R
Exercise instructions
- Use
as.Date()
to convert theastro
vector to a vector containingDate
objects. You will need the%d
,%b
and%Y
symbols to specify theformat
. Store the resulting vector asastro_dates
. - Use
as.Date()
to convert themeteo
vector to a vector withDate
objects. This time, you will need the%B
,%d
and%y
symbols for theformat
argument. Store the resulting vector asmeteo_dates
. - With a combination of
max()
,abs()
and-
, calculate the maximum absolute difference between the astronomical and the meteorological beginnings of a season, i.e.astro_dates
andmeteo_dates
. Simply print this maximum difference to the console output.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Convert astro to vector of Date objects: astro_dates
# Convert meteo to vector of Date objects: meteo_dates
# Calculate the maximum absolute difference between astro_dates and meteo_dates