The centre, in both tools
◈ 12 cardsSUM 6140, AVERAGE 511.67, MEDIAN 445, MODE.SNGL #N/A on the twelve amounts; sum(), mean(), median() in R — and mode() in R is the storage type, never the statistical mode.
Three centres and a total
For a numeric variable the first questions are how much in all and what is typical. The sum answers the first. Three statistics answer the second: the mean (the sum divided by the count), the median (the middle value once sorted), and the mode (the most frequent value). Each is one function in the spreadsheet and one call in R, and the arithmetic is never the examined skill — choosing the function is.
Worked example — the twelve amounts
On D2:D13:
=SUM(D2:D13)→ 6140=AVERAGE(D2:D13)→ 511.67 (6140 / 12 = 511.6667)=MEDIAN(D2:D13)→ 445=MODE.SNGL(D2:D13)→ #N/A
The median deserves a look. Sorted, the amounts are 90, 180, 215, 250, 305, 420, 470, 510, 640, 760, 980, 1320. With an even count there is no single middle value; MEDIAN averages the 6th and 7th: (420 + 470) / 2 = 445. With an odd count it takes the middle one. The mode is a teaching moment: no amount repeats, so there is no most-frequent value and MODE.SNGL returns #N/A — the honest answer, not an error to fix. Apply it to units instead, where 2 appears three times, and it returns 2. MODE.SNGL (single) is the modern name for the legacy MODE; MODE.MULT returns every tied mode when there are several. Both exist in Sheets and Excel.
AVERAGE has the quiet behaviour from Lesson 2.6: a text cell or a blank in the range is ignored, with no warning, and the mean is taken over the cells that held numbers. Arithmetic with + on the same text cell would return #VALUE!; AVERAGE does not.
The same four in R
> sum(orders$amount)
[1] 6140
> mean(orders$amount)
[1] 511.6667
> median(orders$amount)
[1] 445
R prints seven significant digits, so the mean shows as 511.6667 where the spreadsheet showed 511.67. Now the trap that appears on every quiz:
> mode(orders$amount)
[1] "numeric"
mode() in R is not the statistical mode. It returns the storage mode of the object — "numeric", "character", "logical". Base R has no mode function; the idiom is names(which.max(table(x))): build the frequency table, find the largest count, read its name. On units that gives "2" — as text, because table names are text. When the option in a question is mode(x) for "the most frequent value", it is the distractor.
Type five calls, then fill the worksheet
Type the three spreadsheet functions and the two R calls. The worksheet asks for sum, mean (2 dp) and median; the code block reproduces the mean and median with Python's statistics module, where mean and median do what their names say.
CRISP-DM: computing the centre of a variable is data understanding → explore data.