\HeaderA{numeric}{Numeric Vectors}{numeric}
\aliasA{as.numeric}{numeric}{as.numeric}
\aliasA{is.numeric}{numeric}{is.numeric}
\methaliasA{is.numeric.Date}{numeric}{is.numeric.Date}
\methaliasA{is.numeric.POSIXt}{numeric}{is.numeric.POSIXt}
\keyword{classes}{numeric}
\keyword{attribute}{numeric}
\begin{Description}\relax
Creates or coerces objects of type \code{"numeric"}.
\code{is.numeric} is a more general test of an object being
interpretable as numbers.
\end{Description}
\begin{Usage}
\begin{verbatim}
numeric(length = 0)
as.numeric(x, ...)
is.numeric(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{length}] desired length.
\item[\code{x}] object to be coerced or tested.
\item[\code{...}] further arguments passed to or from other methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{numeric} is identical to \code{\LinkA{double}{double}} (and \code{real}).
It creates a double-precision vector of the specified length with each
element equal to \code{0}.

\code{as.numeric} is a generic function, but S3 methods must be
written for \code{\LinkA{as.double}{as.double}}.  It is identical to
\code{as.double} (and \code{as.real}).

\code{is.numeric} is generic: you can write methods to handle
specific classes of objects, see \LinkA{InternalMethods}{InternalMethods}.  It is
\strong{not} the same as \code{\LinkA{is.double}{is.double}}.  Factors are handled
by the default method, and there are methods for classes
\code{"\LinkA{Date}{Date}"} and \code{"\LinkA{POSIXt}{POSIXt}"} (in all three cases
the result is false).  Methods for \code{is.numeric} should only
return true if the base type of the class is \code{double} or
\code{integer} \emph{and} values can reasonably be regarded as
numeric (e.g. arithmetic on them makes sense).
\end{Details}
\begin{Value}
for \code{numeric} and \code{as.numeric} see \code{\LinkA{double}{double}}.

The default method for \code{is.numeric} returns \code{TRUE}
if its argument is of \LinkA{mode}{mode} \code{"numeric"}
(\LinkA{type}{type} \code{"double"} or type \code{"integer"}) and not a
factor, and \code{FALSE} otherwise.  That is,
\code{is.integer(x) || is.double(x)}, or
\code{(mode(x) == "numeric") \&\& !is.factor(x)}.
\end{Value}
\begin{Section}{S4 methods}
\code{as.numeric} and \code{is.numeric} are internally S4 generic and
so methods can be set for them \emph{via} \code{setMethod}.

To ensure that \code{as.numeric}, \code{as.double} and \code{as.real}
remain identical, S4 methods can only be set for \code{as.numeric}.
\end{Section}
\begin{Section}{Note on names}
It is a historical anomaly that \R{} has three names for its
floating-point vectors, \code{\LinkA{double}{double}}, \code{\LinkA{numeric}{numeric}}
and \code{\LinkA{real}{real}}.

\code{double} is the name of the \LinkA{type}{type}.
\code{numeric} is the name of the \LinkA{mode}{mode} and also of the implicit
\LinkA{class}{class}.  As an S4 formal class, use \code{"numeric"} (there is a
deprecated formal class \code{"double"}).

\code{real} is deprecated and should not be used in new code.

The potential confusion is that \R{} has used \emph{\LinkA{mode}{mode}}
\code{"numeric"} to mean \sQuote{double or integer}, which conflicts
with the S4 usage.  Thus \code{is.numeric} tests the mode, not the
class, but \code{as.numeric} (which is identical to \code{as.double})
coerces to the class.
\end{Section}
\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{double}{double}}, \code{\LinkA{integer}{integer}}, \code{\LinkA{storage.mode}{storage.mode}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
as.numeric(c("-.1"," 2.7 ","B")) # (-0.1, 2.7, NA)  +  warning
as.numeric(factor(5:10))
\end{ExampleCode}
\end{Examples}

