R stats::quantile
quantile estimates sample quantiles at supplied probabilities. R's type 7 method interpolates between neighboring ordered observations.
A simple example
stats::quantile
- Start with 1, 2, 3
- Do this Find the 50th percentile
- Result 2
Syntax
quantile(x, probs, na.rm = TRUE, type = 7)
Run this example in R
Save the program as Lesson.R. Use R 4.x.
Rscript --vanilla Lesson.R
Summarize a sample with missing observations
A dataset includes a missing or optional measurement alongside actual numerical values. Make the missing-value policy explicit so a valid zero is not discarded or silently replaced.
values <- c(2, 4, NA, 6, 8)
quartiles <- quantile(values, c(.25, .5, .75), na.rm = TRUE, type = 7, names = FALSE)
cat(paste(quartiles, collapse = " "), "\n", sep = "")
3.5 5 6.5
For the four nonmissing values the median lies halfway between 4 and 6. Specify the type and missing-value policy when results must agree across reporting systems.
R documentation for stats::quantile
Measure a steady cycle time
A classroom robot repeats its cycle in six seconds on every trial. The ordered sample has the same value at every relevant interpolation boundary. What is its upper quartile?
Locate a busy checkout band
Several checkout times tie at the upper end of a small sample. The ordered sample has the same value at every relevant interpolation boundary. What is its upper quartile?