The five number summary is best used for describing data that is skewed.

The examples below will use the wt, weight, variable from the mtcars dataset.

Base R

Base R contains many functions that will calculate summary statistics.

summary()

The summary() function will calculate the five number summary, but is not as flexible as the favstats() function.

summary(mtcars$wt);
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.513   2.581   3.325   3.217   3.610   5.424

fivenum()

The fivenum() function will compute the five number summary, but the output is not as descriptive as the other functions.

fivenum(mtcars$wt);
## [1] 1.5130 2.5425 3.3250 3.6500 5.4240

Tidyverse

The dplyr package makes calculating statistics for multiple groups easy. This process is the same as calculating summary statistics for a sinble group with one additional step. See the dplyr section of the summary statistics page for details.

library(dplyr)
mtcars %>% 
  summarize( Min = min(mpg),
             Q1 = quantile(mpg, .25),
             Avg_MPG = mean(mpg), 
             Q3 = quantile(mpg, .75),
             Max = max(mpg)
             )
##    Min     Q1  Avg_MPG   Q3  Max
## 1 10.4 15.425 20.09062 22.8 33.9

mosaic

The easiest way to calculate summary statistics is to use the favstats() function in the mosaic package.

library(mosaic) # Loads an additional library
favstats(mtcars$wt);
##    min      Q1 median   Q3   max    mean        sd  n missing
##  1.513 2.58125  3.325 3.61 5.424 3.21725 0.9784574 32       0

Mathematicss, Computer Science, and Statistics Department Gustavus Adolphus College