Unit 01.00: The value is the record, not the result
A spreadsheet answers a question once. R answers it every month, the same way, and shows anyone who asks exactly how.
The value is the record, not the result
Almost any single number you need can be got faster in a spreadsheet. What you cannot get from a spreadsheet is an account of how you got it. Six months later, when someone asks why the North figure moved, a spreadsheet offers you a grid of values and your memory. A script offers you the filter, the grouping and the arithmetic, in the order they ran.
That is the trade this course is built on. You will type more than you would in a spreadsheet, and in exchange every step becomes something a colleague can read, question and re-run.
The pipeline below is three steps long: drop the unstaffed rows, group by ward, add up the visits.
# The whole analysis is the script. Nothing is done by hand.
suppressPackageStartupMessages(library(dplyr))
readings <- data.frame(
ward = c("North", "North", "South", "South", "East", "East"),
month = c("Jan", "Feb", "Jan", "Feb", "Jan", "Feb"),
visits = c(412, 455, 388, 401, 502, 498),
staffed = c(TRUE, TRUE, TRUE, FALSE, TRUE, TRUE)
)
result <- readings |>
filter(staffed) |>
group_by(ward) |>
summarise(months = n(), total_visits = sum(visits), .groups = "drop") |>
arrange(desc(total_visits))
print(result)
# Run it again on next month's file and every step repeats identically.
cat("\nSteps a reader can check:", 3, "\n")
cat("Rows dropped by the staffed filter:", nrow(readings) - sum(readings$staffed), "\n")
East totals 1000 across two months and North totals 867. South shows only 388 from a single month, because its February row was unstaffed and the filter removed it. That is the important line of output: 1 row was dropped, and the script says so rather than leaving you to notice that one ward's total covers half the period. A spreadsheet filter would have hidden the row and looked identical.
The mistake this prevents
The mistake is thinking of R as a calculator you type into. Typed into the console, that pipeline gives the same answer and leaves no record. The moment your work matters to someone else, the record is the deliverable and the number is a by-product.
Takeaway
Reach for R when the same question will be asked again, when someone will need to check your reasoning, or when the data is too messy to trust at a glance. For a one-off sum, a spreadsheet is genuinely fine.
