Skip to course content
Free R data course

R Foundations for Data Analysis

Module 04 Activity

Scenario

Turn a wide monthly return into a table that answers a question, using each verb deliberately.

What you build

A wrangling script with the row count reported at every shape change.

Steps

  1. Identify any column name that is really a value and pivot to the long shape before anything else.
  2. Write the pipeline with |>, one verb per line, in the order the steps happen. Break it into named objects wherever the data starts meaning something new.
  3. Use select and filter to shrink first, mutate to derive, then group_by and summarise to change the grain — printing the row count either side of the summarise.
  4. Band a numeric column with case_when(), testing missingness first and supplying .default. Verify one row per band by hand.
  5. Before any join, check the key with anyDuplicated() and choose the join type deliberately. Compare row counts before and after.
  6. Pivot back to wide only for the final table a person will read.

Evidence to hand in

Review checklist