Empirical Quantiles

DESCRIPTION:
Returns a vector of the desired quantiles of the data.

USAGE:
quantile(x, probs = seq(0,1,.25), na.rm = F)

REQUIRED ARGUMENTS:
x:
vector of data. Missing values are not allowed unless na.rm=TRUE.

OPTIONAL ARGUMENTS:
probs:
vector of desired probability levels. Values must be between 0 and 1 inclusive. The default produces a "five number summary": the minimum, lower quartile, median, upper quartile, and maximum of x.
na.rm:
logical flag: should missing values be removed before computation?

VALUE:
vector of empirical quantiles corresponding to the probs levels in the sorted x data.

DETAILS:
The algorithm linearly interpolates between order statistics of x, assuming that the ith order statistic is the (i-1)/(length(x)-1) quantile. The algorithm uses partial sorting, hence is quickly able to find a few quantiles even of large datasets.

SEE ALSO:
diff , function , median , ppoints , qqplot , rank , testscores .

EXAMPLES:
quantile(car.miles)     # five number summary

quantile(testscores[,1], c(.33,.67)) # 33% and 67% quantiles of # data from testscores

quar <- diff(quantile(testscores[,1], c(.25, .75))) # interquartile range

# create function iqr iqr <- function (x) diff(quantile(x, c(.25, .75))) iqr(car.miles) # returns 23