
Last chance! 50% off unlimited learning
Sale ends in
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.quantile(x, ...)## S3 method for class 'default':
quantile(x, probs = seq(0, 1, 0.25), na.rm = FALSE,
names = TRUE, type = 7, ...)
NA
and NaN
values are not
allowed in numeric vectors unless na.rm
is TRUE
.NA
and NaN
's
are removed from x
before the quantiles are computed.names
attribute. Set to FALSE
for speedup with many probs
.length(probs)
is returned;
if names = TRUE
, it has a names
attribute. NA
and NaN
values in probs
are
propagated to the result.
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 sort
in
quantile
can be applied to complex vectors which (apart
from ties) will be ordered on their real parts.
There is a method for the date-time classes (see
"POSIXt"
). Types 1 and 3 can be used for class
"Date"
and for ordered factors.
Hyndman, R. J. and Fan, Y. (1996) Sample quantiles in statistical packages, American Statistician 50, 361--365.
ecdf
for empirical distributions of which
quantile
is an inverse;
boxplot.stats
and fivenum
for computing
other versions of quartiles, etc.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)
Run the code above in your browser using DataLab