Reference solution for the Chapter 8 Practice Demo Lab (Tasks 1–6 of Lab: Combine three forestry sources). The graded Canvas lab has its own private answer key.
Comparable across the two forestry files: a year and an area in hectares. The air-quality file has no area — it is measured on a different axis (hourly pollutant concentrations), so it is the odd one out.
bc_h <- bc |>transmute(province ="British Columbia",year = Fiscal_Year, area_ha = Harvested_ha)on_h <- on |>transmute(province ="Ontario",year =2021L, area_ha = SumOfTotalHa)
Task 3 — Stack with bind_rows()
combined <-bind_rows(bc_h, on_h)kable(bind_rows(head(bc_h, 2), head(on_h, 2)),caption ="Uniform schema: province, year, area_ha (first rows of each source).")
Uniform schema: province, year, area_ha (first rows of each source).
province
year
area_ha
British Columbia
1987
242182.000
British Columbia
1988
251557.320
Ontario
2021
2184.069
Ontario
2021
26085.574
Task 4 — Diagnose
count(combined, province) # both provinces present?
# A tibble: 2 × 2
province n
<chr> <int>
1 British Columbia 37
2 Ontario 179
colSums(is.na(combined)) # any unexpected NAs after the bind?
province year area_ha
0 0 0
Both provinces appear (BC = 37 rows, Ontario = 179 rows), and there are no unexpected NAs.
Task 5 — Reflect (the decisions the code cannot make)
Units: both areas are hectares — good; if one had been km² we would have had to convert first.
Time aggregation: BC is a yearly time series (1987–2023); Ontario is a single 2021 snapshot cross-classified by category. Stacking them treats very different time scopes as one column — a judgement call.
Scope: BC Harvested_ha is area harvested per year; Ontario SumOfTotalHa is total forest area by category. They are not the same quantity — the combined table is only meaningful if the reader is told this.
Task 6 — Submit
Submit the combined tibble (as a kable), a one-paragraph note on the Task 5 decisions, and all group members’ names. (Graded lab: follow Canvas.)