Reference solution for the Chapter 6 Practice Demo Lab (Tasks 1–6 of Lab: Clean the air-quality file together). Check your own attempt against it. The graded Canvas lab has its own private answer key.
Task 1 — Inspect together (the six moves)
air <-read_csv(here("data", "airdata3.csv"), show_col_types =FALSE)dim(air) # rows x columns
The file has 11904 rows × 27 columns; 14 columns are 100 % missing and 13 carry data. glimpse(air) shows the key columns: location (the monitoring station), Date, Time, and pollutant columns including O3.
Task 2 — Drop the redundant columns
Drop the two spreadsheet index columns and every 100 %-missing column:
air2 <- air |>select(-`...1`, -`Unnamed: 0`) |># drop the spreadsheet index columnsselect(where(~!all(is.na(.)))) # drop columns that are entirely NAncol(air2) # columns remaining
That leaves the 11 columns that actually contain data — location, Date, Time, O3, and the other measured pollutants.
Task 3 — Parse the date
air3 <- air2 |>mutate(date =mdy(Date))sum(is.na(air3$date)) # how many dates failed to parse?
[1] 0
mdy(Date) parses every row — the failure count is 0 — because the file stores dates as month/day/year (e.g., 1/1/2000). If any had failed, they would show up as NA in this count.
Task 4 — Filter and group: mean O₃ per station (sorted)
Mean hourly ozone (O3, ppb) by station, January 2000, highest first.
location
mean_o3
n_hours
Langley Central
17.7
732
Maple Ridge Golden Ears School
11.3
564
Richmond South
10.5
732
North Delta
10.3
731
Vancouver International Airport #2
10.2
727
Burnaby South
9.1
732
Vancouver Kitsilano
7.5
731
Port Moody Rocky Point Park
6.1
728
Task 5 — Discuss the result
Langley Central has the highest mean O₃ (17.7 ppb) for the month. That is consistent with Metro Vancouver geography: ozone is a secondary pollutant that forms downwind of traffic emissions, so cleaner-air / more suburban or elevated sites often record higher ozone than the busiest downtown stations — the opposite of what many students expect.
Task 6 — Submit
Each group submits: the final pipeline (Tasks 2–4 as one Quarto chunk), the station-ranked table from Task 4, and a one-sentence interpretation (Task 5), with all members’ names. (For the graded Canvas lab, follow the Canvas instructions.)