Discussion
Use these questions after the eight lessons or during a paired review. Turn one answer into a practical next step using Additional Material.
Review a Research Workflow
- Could a colleague locate and rerun your saved script with a fresh R session?
- Which identifiers, units and object types did you check before selecting or calculating?
- What known value would reveal an error in a reusable function?
- When did vectorisation suit the task, and when did a loop make separate outputs clearer?
- Which observations contribute to your summary, and what weighting does it use?
- How did you account for unmatched records, missing values or an empty selection?
- What does your final figure establish, and what interpretation would exceed the data?
Why a Data-Frame Row Is Not Necessarily a Numerical Vector
A data frame can combine an identifier with numerical measurements. Selecting a whole row retains that mixed structure; passing it directly to mean() does not establish a meaningful average. First decide which columns represent comparable measurements in the same units.
This fictional example records two repeated mass measurements in grams:
measurements <- data.frame(
sample_id = c("sample_01", "sample_02"),
mass_g_1 = c(2.1, 2.4),
mass_g_2 = c(2.3, NA)
)
mass_columns <- measurements[c("mass_g_1", "mass_g_2")]
rowMeans(mass_columns)The first mean is 2.2 g; the second remains missing with the default missing-value handling. rowMeans(mass_columns, na.rm = TRUE) would answer a different question by using the available value in the second row. Record that decision explicitly. Keep sample_id beside any derived result and do not convert an entire mixed row with as.numeric() to suppress an error.
Compare this with lesson 2’s object structures. The official row and column summaries documentation explains supported inputs and missing-value arguments.
Room Discussion: An Empty Result
The inherited Gapminder exercise asks for 2012 and uses pop <= 3. What must be checked before changing the code? Ask pairs to inspect available years and population units, then take two explanations from the room. A well-formed filter may correctly return no rows because the dataset cannot support the request. Agree a revised question or data source; do not silently change a threshold or substitute another year.
Review a Notebook and Dashboard Together
Use the shared project and compare:
- Which source, country/year selection and helper support the notebook and app?
- Does a changed parameter/control update the text, table and figure consistently?
- What happens when no country is selected, a year is unavailable or a source file is missing?
- Does the downloaded CSV retain identifiers and unrounded measurements?
- What must be shared to rerun the notebook or run the live app?
For a five-minute room task, spend one minute choosing a case, two minutes trying it, one minute comparing with a partner and one minute hearing two pairs report. Keep a check, a correction and an unresolved question.