Compute the sample median.
Median(x, ...)"Median"(x, breaks, ...)"Median"(x, weights = NULL, na.rm = FALSE, ...)
- an object for which a method has been defined, or a numeric vector containing the values whose median is to be computed.
- a numerical vector of weights the same length as
xgiving the weights to use for elements of
- breaks for calculating the mean for classified data as composed by
- a logical value indicating whether
NAvalues should be stripped before the computation proceeds.
- further arguments passed to or from other methods.
This is a generic function for which methods can be written. However,
the default method makes use of
mean from package base all of which are generic, and so
the default method will work for most classes
"Date") for which a median is a reasonable
The default method returns a length-one object of the same type as
x, except when
xis integer of even length, when the result will be double.If there are no values or if
na.rm = FALSEand there are
NAvalues the result is
NAof the same type as
x(or more generally the result of
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
quantile for general quantiles.
Median(1:4) # = 2.5 [even number] Median(c(1:3, 100, 1000)) # = 3 [odd, robust] # Approximation for classified data breaks <- seq(10,70, 10) Median( Freq(cut(d.pizza$temperature, breaks=breaks)), breaks=breaks) # compared to Median(d.pizza$temperature)