In-class exercises

Instructions

Complete one of the following sets of activities. Save the resulting scripts, and share these with Gaurav via email.

For students new to programming

Follow the R for Ecologists lessons on Youtube. Focus on Lessons 1–4.

Note that the files used by the instructor are available here: https://www.rforecology.com/uploads/Basics_of_R_course_materials.zip

Save the R code you write through these exercises for future reference.

For students with programming experience.

Without the use of any AI tools, answer the questions belwo to the best of your abilities. You are welcome to use books, stack overflow, built-in R help tools, but for now, please don’t ask other people for help, and definitely don’t use generative AI tools to solve the problem. The goal of this is for me to get a good sense of your starting point in R so that I can accurately calibrate lessons for the remainder of the semester.

These questions make use of the palmerpenguins package, which you can install with install.packages(palmerpenguins). Once installed and loaded, the penguins dataframe will be immediately available in your environment.

  1. Write code to create the following graph:

  1. As loaded, the dataframe is in wide format. Write code to reshape into long format, each individual penguin’s bill length, bill depth, flipper length, and body mass appear on separate rows. Also make sure that the final long dataframe has an additional column penguin_id that identifies which individual penguin each measurement corresponds to. The resulting dataframe should appear as follows:
# A tibble: 1,376 × 7
   species island    sex     year penguin_id name               value
   <fct>   <fct>     <fct>  <int>      <int> <chr>              <dbl>
 1 Adelie  Torgersen male    2007          1 bill_length_mm      39.1
 2 Adelie  Torgersen male    2007          1 bill_depth_mm       18.7
 3 Adelie  Torgersen male    2007          1 flipper_length_mm  181  
 4 Adelie  Torgersen male    2007          1 body_mass_g       3750  
 5 Adelie  Torgersen female  2007          2 bill_length_mm      39.5
 6 Adelie  Torgersen female  2007          2 bill_depth_mm       17.4
 7 Adelie  Torgersen female  2007          2 flipper_length_mm  186  
 8 Adelie  Torgersen female  2007          2 body_mass_g       3800  
 9 Adelie  Torgersen female  2007          3 bill_length_mm      40.3
10 Adelie  Torgersen female  2007          3 bill_depth_mm       18  
# ℹ 1,366 more rows