Descriptive Statistics with R
September 14, 2026
Note
They describe what is in the data. By themselves, they do not explain why a pattern occurred or predict what will happen next.
| Question | Grocery-bill example |
|---|---|
| Can we trust the data? | Flag a $10,000 bill when most bills are $50–$150. |
| What is typical? | Compare the mean and median bill. |
| How much do values vary? | Start with the range; later, compare other measures of spread. |
| Could one unusual bill distort the summary? | Compare the mean and median, then inspect the distribution. |
Tip
A summary starts the investigation; it does not replace the original data.
| Measure | Meaning of “typical” | Best suited to | Important feature |
|---|---|---|---|
| Mean | Balance point | Numeric values | Uses every value |
| Median | Middle after sorting | Numeric values | Resists extreme values |
| Mode | Most frequent value | Numeric or categorical values | May tie or not be unique |
\[ \bar{x} = \frac{x_{1} + x_{2} + \cdots + x_{n}}{n} \]
mean(x) calculates it directly.Note
Because the mean uses every value, one extreme value can shift it substantially.
\[ \bar{x}_{w} = \frac{w_{1}x_{1} + w_{2}x_{2} + \cdots + w_{n}x_{n}}{w_{1} + w_{2} + \cdots + w_{n}} \]
| Course component | Score | Weight |
|---|---|---|
| Homework | 90 | 40% |
| Exam | 80 | 60% |
For a numeric vector sorted from smallest to largest, \(x_{(1)} \le x_{(2)} \le \cdots \le x_{(n)}\),
\[ \operatorname{median}(x)= \begin{cases} x_{\left(\frac{n+1}{2}\right)}, & n \text{ is odd},\\[4pt] \dfrac{x_{\left(\frac{n}{2}\right)}+x_{\left(\frac{n}{2}+1\right)}}{2}, & n \text{ is even}. \end{cases} \]
Warning
mode() reports an object’s storage mode; it does not calculate the statistical mode.modeest, provides the mfw(x) function that calculate the mode of values in vector x.\[ \text{range width} = \max(x)-\min(x) \]
Note
The range is highly sensitive to extremes: replacing 100 with 200 changes the width from 40 to 140.
\[ s^2=\frac{\sum_{i=1}^{n}(x_i-\bar{x})^2}{n-1} \]
| 60 | 70 | 80 | 90 | 100 | |
|---|---|---|---|---|---|
| Deviation from mean 80 | −20 | −10 | 0 | 10 | 20 |
| Squared deviation | 400 | 100 | 0 | 100 | 400 |
var(x) calculates the sample variance, using \(n-1\) in the denominator.\[ s=\sqrt{s^2} \]
250 points²variancesquare rootundo the square15.8 pointsstandard deviationscores[2]one positionscores[c(2, 5)]several positionsscores[scores >= 85]values meeting a condition[] hold the selection rule.| Position | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Value | 10 | 20 | 30 | 40 | 50 | 60 |
my_vector[2] means “the value in position 2,” not “the value 2.”c(...) to select several values.3:5 is shorthand for the consecutive positions c(3, 4, 5).TRUETRUE or FALSE for each value; brackets keep the TRUE positions.