The generic function
quantile produces sample quantiles
corresponding to the given probabilities.
The smallest observation corresponds to a probability of 0 and the
largest to a probability of 1.
## S3 method for class 'default': quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE, names = TRUE, type = 7, ...)
- numeric vector whose sample quantiles are wanted, or an
object of a class for which a method has been defined (see also
NaNvalues are not allowed in numeric vectors unless
- numeric vector of probabilities with values in $[0,1]$. (Values up to 2e-14 outside that range are accepted and moved to the nearby endpoint.)
- logical; if true, any
NaN's are removed from
xbefore the quantiles are computed.
- logical; if true, the result has a
namesattribute. Set to
FALSEfor speedup with many
- an integer between 1 and 9 selecting one of the nine quantile algorithms detailed below to be used.
- further arguments passed to or from other methods.
A vector of length
length(probs) is returned;
names = TRUE, it has a
The default method works with classed objects sufficiently like
numeric vectors that
sort and (not needed by types 1 and 3)
addition of elements and multiplication by a number work correctly.
Note that as this is in a namespace, the copy of
quantile can be applied to complex vectors which (apart
from ties) will be ordered on their real parts.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in statistical packages, American Statistician 50, 361--365.
quantile(x <- rnorm(1001)) # Extremes & Quartiles by default quantile(x, probs = c(0.1, 0.5, 1, 2, 5, 10, 50, NA)/100) ### Compare different types p <- c(0.1, 0.5, 1, 2, 5, 10, 50)/100 res <- matrix(as.numeric(NA), 9, 7) for(type in 1:9) res[type, ] <- y <- quantile(x, p, type = type) dimnames(res) <- list(1:9, names(y)) round(res, 3)