Skip to course content
Free R data course

R Foundations for Data Analysis

Unit 06.00: Centre, spread, and the gap between them

The mean is one number about a column. It is rarely the most honest one.

Centre, spread, and the gap between mean and median

Descriptive statistics answer two questions: where is the middle, and how spread out is it. The mean and the median answer the first differently — the mean uses every value's size, the median only its rank — so one unusual value moves the mean a long way and the median barely at all.

That difference is itself a finding. When the mean and median are close, the values are fairly symmetric. When they are far apart, something is pulling one tail, and that something is usually worth looking at.

For spread, the range gives the extremes, the quartiles show where the middle half sits, and the standard deviation summarises typical distance from the mean — which, like the mean, is sensitive to outliers.

This block summarises seven days, one of which is unusual.

visits <- c(412, 455, 388, 401, 502, 498, 1840)

cat("n          :", length(visits), "\n")
cat("Mean       :", round(mean(visits), 1), "\n")
cat("Median     :", median(visits), "\n")
cat("Range      :", paste(range(visits), collapse = " to "), "\n")
cat("Quartiles  :", paste(round(quantile(visits, c(0.25, 0.5, 0.75)), 1), collapse = "  "), "\n")
cat("SD         :", round(sd(visits), 1), "\n\n")

# One unusual day moves the mean a long way and the median barely at all.
without <- visits[visits < 1000]
cat("Excluding the 1840 day:\n")
cat("  Mean  :", round(mean(visits), 1), "->", round(mean(without), 1), "\n")
cat("  Median:", median(visits), "->", median(without), "\n")
cat("  SD    :", round(sd(visits), 1), "->", round(sd(without), 1), "\n\n")

cat("Report the mean AND the median when they disagree. The gap is the finding.\n")

With the unusual day included, the mean is 642.3 and the median is 455 — a gap of nearly 190 that announces the skew before you have looked at a single value. Removing the 1840 day moves the mean to 442.7 and the median only to 433.5. The standard deviation is the most dramatic: 530.1 down to 49.8, a tenfold change from one row out of seven.

The mistake this prevents

The mistake is reporting the mean alone. On this data it describes no day that actually occurred: six days sat between 388 and 502, and the average is 642.

Takeaway

Report the mean, the median and a measure of spread together. When the mean and median disagree, investigate the values responsible before choosing which to quote.