median
Median

Description

Calculates the median of the input. The function median is generic.

Usage

median(x, na.rm = FALSE, ...)
## Default S3 method:
median(x, na.rm = FALSE, ...)

Arguments

x a numeric or logical atomic vector. Missing values (NA) are allowed.
na.rm a logical value that specifies if missing values should be removed before computation.
... extra arguments that are ignored by the core methods for median but may be used by methods added by packages.

Details

If x contains any NAs, the result will be NA unless na.rm = TRUE. median is a generic function, only a default method is implemented now.
Value
returns the median of x, where the value has the same type as x. If the length of x is even the return value is the mean of the two middle elements. For even length logical vectors, this mean is 0, 0.5 or 1.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language: A Programming Environment for Data Analysis and Graphics. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
mad, mean, quantile.
Examples
medMileage <- Sdatasets::fuel.frame[, "Mileage"]  # median Mileage value
apply(Sdatasets::ozone.data, 2, median)  # median of all columns
median(c(1, 2, NA), na.rm = TRUE)
## [1] 1.5
median(c(1, 2, 6, 4))
## [1] 3
Package stats version 6.0.0-69
Package Index