R-ecology-lesson icon indicating copy to clipboard operation
R-ecology-lesson copied to clipboard

Add challenge to 'Formatting Dates' section of 'Starting with Data'

Open alexis-catherine opened this issue 4 years ago • 1 comments

The only section of the Starting with Data section is the Formatting Dates. One thought is a challenge could be to re-write the ymd() code with one of ymd() sister functions. It would help demonstrate how flexible the different functions are and how if your data is in a slightly different format it isn't an insurmountable problem.

Challenge:

  1. Different countries and organizations have different ways they represent dates month-day-year, day-month-year, and year-day-month are all common variants. ymd() is part of a family of functions that can parse dates in different formats. Use the help function or the help operator to read through the documentation, pick one of the sister functions, and rewrite the code to parse the dates using that function instead.

alexis-catherine avatar Apr 13 '20 19:04 alexis-catherine

A common issue is plotting data versus elapsed, vs. absolute, time or date. A further challenge suggestion: 2. Generate a new column, days_elapsed, by subtracting the lowest value of surveys$date from all other values of surveys$date. Hint: Base R function min(c(1, 2, 0, NA) , na.rm) gives the minimum value of the vector c(1, 2, 0, NA)

Answer: surveys$days_elapsed <- surveys$date - min(surveys$date, na.rm = TRUE) str(surveys$days_elapsed)

A common error would be assuming that surveys$date[1] is the minimum value, or questions over the units of the output, which in this case are days.

GitHubDoug avatar Jun 27 '22 18:06 GitHubDoug