Library contents

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

  1. Start with 1, 2, 3
  2. Do this Find the 50th percentile
  3. Result 2
The middle value of the three ordered numbers is 2.

Syntax

R 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.

From the programcat(paste(quartiles, collapse = " "), "\n", sep = "")
Result3.5 5 6.5
Lesson.R
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 = "")
Output
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

Advertisements

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?

Given6 · 6 · 6 · 6 · 6
Worked result6.0

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?

Given2 · 4 · 8 · 8 · 8 · 8 · 8
Worked result8.0