Skip to course content
Free R data course

R Foundations for Data Analysis

Unit 06.03: The report table is not the analysis table

A table for a reader is not the table you computed. It has been sorted, rounded and renamed on purpose.

Four decisions, all of them visible in the code

The analysis table and the report table are different objects. Turning one into the other means deciding how many decimals are meaningful, what order the rows should read in, what the columns should be called in English, and which columns a reader needs in order to judge the numbers.

That last one is where tables mislead most often. A rate without its denominator, or a mean without its count, invites a conclusion the data cannot support — and leaving the column out is a decision, just an invisible one.

Doing all four in code rather than in a word processor means the table regenerates when the data changes, and every decision stays reviewable.

This block turns an analysis table into a report table with kable().

suppressPackageStartupMessages({library(dplyr); library(knitr)})

by_ward <- data.frame(
  ward      = c("North", "South", "East"),
  months    = c(3L, 2L, 1L),
  total     = c(1298, 789, 502),
  mean      = c(432.7, 394.5, 502.0),
  residents = c(12400, 9800, 15100)
)

report_table <- by_ward |>
  mutate(per_1000 = round(total / months / residents * 1000, 1)) |>
  arrange(desc(per_1000)) |>
  select(Ward = ward,
         `Months reported` = months,
         `Mean monthly visits` = mean,
         `Visits per 1,000 residents` = per_1000)

cat(kable(report_table, format = "simple"), sep = "\n")

cat("\nFour decisions were made above, all of them visible in the code:\n")
cat("  rounding to 1 decimal; sorting by rate; renaming columns for a reader;\n")
cat("  and keeping `Months reported` so the rate can be judged.\n")

The output sorts South (40.3 per 1,000) above North (34.9) and East (33.2), rounds to one decimal, and renames the columns to phrases a reader understands. Critically it keeps Months reported, which shows East's figure resting on 1 month while North's rests on 3 — the one column that stops the ranking being read as settled.

The mistake this prevents

The mistake is exporting the raw analysis table with its programming names and full precision. per_1000 = 34.87096774 tells a reader that nobody thought about what they needed.

Takeaway

Round to the precision the measurement supports, sort by what the reader cares about, rename columns into English, and keep the denominators. Build the table in code so it survives the next data refresh.