Dates and times

Author

Jeffrey R. Stevens

Published

March 22, 2023

For these exercises, we’ll use the dates data set.

  1. Load tidyverse, import dates.csv to dates, and view the data set.
# >
  1. Convert birth_date to a date object and resave dates.
# >
  1. Create a column called time1 that converts test1 to datetime and change the time zone to “America/Chicago”.
# >
  1. Calculate each participant’s age in years at the time of test 1, rounded to 1 decimal place, stored in age and resave dates.
# >
  1. Calculate the number of days between test 1 and test 2 for each participant and label this column test_diff (and resave dates).
# >
  1. Create dates2 that subsets the participants who were born after January 1, 1970.
# >
  1. Create a column named diff_text that writes the following sentence for each participant in dates2: “Participant [insert id] (age: [insert age]) had test 1 on [insert test1] and test 2 on [insert test2], which were [insert test_diff] days apart.”
# >