\HeaderA{median}{Median Value}{median}
\methaliasA{median.default}{median}{median.default}
\keyword{univar}{median}
\keyword{robust}{median}
\begin{Description}\relax
Compute the sample median.
\end{Description}
\begin{Usage}
\begin{verbatim}
median(x, na.rm = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an object for which a method has been defined, or a
numeric vector containing the values whose median is to be computed.
\item[\code{na.rm}] a logical value indicating whether \code{NA}
values should be stripped before the computation proceeds.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This is a generic function for which methods can be written.  However,
the default method makes use of \code{sort} and \code{mean}, both of
which are generic, and so the default method will work for most
classes (e.g. \code{"\LinkA{Date}{Date}"}) for which a median is a reasonable
concept.
\end{Details}
\begin{Value}
The default method returns a length-one object of the same type as
\code{x}, except when \code{x} is integer of even length, when the
result will be double.

If there are no values or if \code{na.rm = FALSE} and there are \code{NA}
values the result is \code{NA} of the same type as \code{x} (or more
generally the result of \code{x[FALSE][NA]}).
\end{Value}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{quantile}{quantile}} for general quantiles.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
median(1:4)# = 2.5 [even number]
median(c(1:3,100,1000))# = 3 [odd, robust]
\end{ExampleCode}
\end{Examples}

