Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

quantile() in R: Syntax, probs, type 1-9 and Worked Examples

Compute quantiles in R with quantile(): syntax, probs, na.rm, the nine type definitions and a worked example of cross-software differences.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: in R, quantile(x, probs = c(0.25, 0.5, 0.75)) returns sample quantiles of the numeric vector x at the probabilities you give. The function belongs to the base stats package, so nothing needs installing beyond R itself. The detail that matters for a methods section is the type argument: R uses type 7 by default, and other statistical packages use different definitions, so the same data can give slightly different quartiles in different software.

What quantile() is used for in research

The R reference describes quantile as the generic function that “produces sample quantiles corresponding to the given probabilities.” Researchers use it to report medians and quartiles, to find cut points such as the 90th percentile of a measurement, to trim or winsorise outliers, and to build the inputs for box plots. For the conceptual background, see percentile and quantile, box plots and the IQR and descriptive statistics. The same function appears under several search phrasings (quantiles in R, R quantiles, quantile function in R); they all refer to stats::quantile() covered below. It is distinct from quantile regression, covered in quantile regression analysis, and from the theoretical distribution functions such as qnorm (see pnorm in R for the companion cumulative function).

Install or access

R is obtained from CRAN, the Comprehensive R Archive Network, at cran.r-project.org. quantile() is part of the stats package, which is loaded by default in an R session, so no library() call is needed. Documentation for the function is available offline with ?quantile and online in the R stats reference (read 2026-11-07).

Step by step: computing quantiles in R

The documented usage is:

quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, digits = 7, ...)
  1. Put your data in a numeric vector. x <- c(2, 4, 4, 5, 7, 9, 12, 15)
  2. Call the function with defaults. quantile(x) returns the minimum, the quartiles and the maximum (probabilities 0, 0.25, 0.5, 0.75, 1), labelled 0%, 25%, and so on.
  3. Choose your own probabilities. quantile(x, probs = c(0.1, 0.9)). Each value in probs must lie between 0 and 1. A percentile of 90 is written 0.9, not 90.
  4. Handle missing values. quantile(x, na.rm = TRUE). By default na.rm = FALSE, and the reference states that NA and NaN values are not allowed in numeric vectors unless na.rm is TRUE, so a vector with missing values fails rather than silently dropping them.
  5. Select the definition. quantile(x, probs = 0.9, type = 6). See the next section.
  6. Get plain numbers. quantile(x, probs = c(0.25, 0.75), names = FALSE) drops the labels; the reference notes names = FALSE is faster when you pass many probabilities.

The type argument: nine definitions of a sample quantile

Sample quantiles are not defined uniquely, and type selects among nine algorithms from Hyndman and Fan (1996). The R reference states that the default, type 7, is the one used by S and by R before version 2.0.0. The reference records these correspondences:

Type Definition (per R reference) Software noted in the reference
1 Inverse of the empirical distribution function –
2 As type 1, but averaging at discontinuities SAS default
3 Nearest even order statistic SAS default until about 2010
4 Linear interpolation of the empirical CDF, p(k) = k/n –
5 Piecewise linear, knots midway through the steps Popular with hydrologists
6 p(k) = k/(n + 1) Minitab and SPSS
7 p(k) = (k – 1)/(n – 1) R default; S
8 Approximately median-unbiased Recommended by Hyndman and Fan
9 Approximately unbiased for the expected order statistics if x is normally distributed –

Worked example

Take the sorted vector x = 2, 4, 4, 5, 7, 9, 12, 15 (n = 8) and ask for the 0.9 quantile.

  • Type 7 (R default): the position is h = (n – 1)p + 1 = 7 × 0.9 + 1 = 7.3, so the result interpolates 30% of the way from the 7th value (12) to the 8th (15): 12 + 0.3 × 3 = 12.9.
  • Type 6 (Minitab, SPSS): the position is (n + 1)p = 8.1, which is beyond the largest observation, so the result is capped at the maximum, 15.
  • Type 1: the smallest observation whose empirical CDF reaches 0.9 is the 8th, since 7/8 = 0.875 < 0.9, giving 15.

The same data therefore yield 12.9 or 15 for the 90th percentile depending on the definition. When results are compared with SPSS, Minitab or SAS output, state the type in the methods section, for example “quartiles computed with R’s quantile(), type 7 (default).” For the 0 and 1 probabilities the reference notes that 0% and 100% equal min(x) and max(x) for all types.

Output and how to read it

With names = TRUE (the default) the result is a named numeric vector, where each name is the probability as a percentage, formatted using the digits argument. So quantile(x, probs = 0.9) prints a single value labelled 90%. To compute an interquartile range, subtract the 25% from the 75% value, or see the interquartile range in R. Probabilities outside [0, 1] produce an error. An NA inside probs is passed through to the output as NA, as the reference’s example probs = c(0.1, 0.5, 1, 2, 5, 10, 50, NA)/100 shows.

Troubleshooting

  • Error about missing values: add na.rm = TRUE, then report how many observations were removed.
  • Error about probabilities: convert percentages to proportions (90 becomes 0.9).
  • Quartiles differ from SPSS, Minitab or SAS: set type to match (6 for the Minitab and SPSS definition noted in the reference) or document that the packages use different definitions.
  • Need a grouped result: quantile() works on one vector, so apply it per group, for example with tapply(x, group, quantile) or aggregate().

Free alternatives

Tool Equivalent
R (stats package) quantile(x, probs, type)
Python with NumPy numpy.quantile(a, q)
Python with pandas Series.quantile(q)

For a wider comparison of no-cost analysis software, see free statistical software; for the SPSS route, see descriptive statistics in SPSS.

FAQ

What does quantile() return by default in R?

The minimum, first quartile, median, third quartile and maximum, because the default is probs = seq(0, 1, 0.25) with type = 7.

How do I get the 95th percentile in R?

quantile(x, probs = 0.95), adding na.rm = TRUE if the data contain missing values.

Why do my quartiles differ from SPSS or SAS?

The packages use different sample-quantile definitions. R’s default is type 7; the R reference lists type 6 for Minitab and SPSS and types 2 and 3 for SAS. Match the type or report which one you used.

Is quantile() the same as quantile regression?

No. quantile() summarises one variable’s distribution; quantile regression models how a conditional quantile depends on predictors.

Sources

  • R Core Team, quantile: Sample Quantiles, R stats package reference (read 2026-11-07).
  • Hyndman, R. J. and Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician 50(4), 361-365. doi:10.1080/00031305.1996.10473566.
  • The Comprehensive R Archive Network, cran.r-project.org (read 2026-11-07).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about quantile() in R: Syntax, probs, type 1-9 and Worked Examples

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →