Reference solution for the Chapter 7 Practice Demo Lab (Tasks 1–5 of Lab: Produce a summary report together). Assumes air_clean from Chapter 6. The graded Canvas lab has its own private answer key.
Task 1 — Agree on the question
Worked example: “Which day in January 2000 was the worst air-quality day, on average across all stations?” (measured by mean hourly O₃). Any of the three suggested questions works.
Task 2 — Build the summary
worst_days <- air_clean |>filter(!is.na(O3)) |>group_by(date) |>summarise(mean_o3 =round(mean(O3), 1),n_readings =n(),.groups ="drop") |>arrange(desc(mean_o3))kable(head(worst_days, 5),caption ="Days with the highest mean hourly O3 (ppb) across all stations, Jan 2000.")
Days with the highest mean hourly O3 (ppb) across all stations, Jan 2000.
date
mean_o3
n_readings
2000-01-09
25.5
190
2000-01-08
25.2
189
2000-01-04
21.9
188
2000-01-01
18.0
190
2000-01-02
17.6
189
Task 3 — Reshape if useful
This summary has one grouping variable (date), so it is already a readable ranked table — no pivot_wider() needed. (If you had grouped by two variables — say date × location — you would pivot_wider() so each station is a column.)
Task 4 — Caption it
January 09, 2000 was the worst average-ozone day of the month, at 25.5 ppb mean across stations.
Task 5 — Submit
Submit the dplyr pipeline (Task 2), the rendered table, the one-sentence caption, and all group members’ names. (Graded lab: follow Canvas.)