Calculates the five number summary of a vector of data or of each column of a matrix of data, using the estimators of the lower quartile, median and upper quartile in the STAT002 notes.

five_number(x, type = 6, na.rm = FALSE)

Arguments

x

A numeric vector or matrix.

type

Argument type used in the call to quantile to estimate the 25%, 50% and 75% quantiles.

na.rm

A logical scalar. If true, any NA and NaNs are removed from x before the sample quantiles are computed.

Value

A numeric vector (if the input was a vector) or matrix (if the input was a matrix).

Details

The five number summary contains the sample minimum and maximum and estimates of the lower quartile, median and upper quartile, i.e. the 25%, 50% and 75% quantiles. These quantiles are estimated using the quantile function. By default, type = 6 is used in the call to quantile in order to use the estimator defined in the STAT002 notes.

See also

quantile for calculating sample quantiles.

Examples

birth_times <- ox_births[, "time"]
five_number(birth_times)
#>   min   25%   50%   75%   max 
#>  1.50  4.90  7.50  9.75 19.00 

# Note: summary() uses type = 7 in the call to quantile()
five_number(birth_times, type = 7)
#>   min   25%   50%   75%   max 
#>  1.50  4.95  7.50  9.75 19.00 
summary(birth_times)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>   1.500   4.950   7.500   7.723   9.750  19.000