R-ecology-lesson
R-ecology-lesson copied to clipboard
Add challenge to 'Formatting Dates' section of 'Starting with Data'
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:
- 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.
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.