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
- Identify any column name that is really a value and pivot to the long shape before anything else.
- 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. - Use
selectandfilterto shrink first,mutateto derive, thengroup_byandsummariseto change the grain — printing the row count either side of the summarise. - Band a numeric column with
case_when(), testing missingness first and supplying.default. Verify one row per band by hand. - Before any join, check the key with
anyDuplicated()and choose the join type deliberately. Compare row counts before and after. - Pivot back to wide only for the final table a person will read.
Evidence to hand in
- The long-form table and what column name was really a value.
- The pipeline, one verb per line.
- Row counts either side of the summarise.
- The banded column, with one verified row per band.
- The key check and the row counts around the join.
- The final wide table.
Review checklist
- No column name in the working data is a date, a category or a year.
.groups = 'drop'is used, or the grouping is dropped deliberately.- The
case_when()tests missingness first and ends with.default. anyDuplicated()was run on the join key before joining.- Row counts are reported around both the summarise and the join.
