Rev 43450 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/numeric.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Development Team% Distributed under GPL 2 or later\name{numeric}\title{Numeric Vectors}\alias{numeric}\alias{as.numeric}\alias{is.numeric}\alias{is.numeric.Date}\alias{is.numeric.POSIXt}\description{Creates or coerces objects of type \code{"numeric"}.\code{is.numeric} is a more general test of an object beinginterpretable as numbers.}\usage{numeric(length = 0)as.numeric(x, \dots)is.numeric(x)}\arguments{\item{length}{desired length.}\item{x}{object to be coerced or tested.}\item{\dots}{further arguments passed to or from other methods.}}\details{\code{numeric} is identical to \code{\link{double}} (and \code{real}).It creates a double-precision vector of the specified length with eachelement equal to \code{0}.\code{as.numeric} is a generic function, but S3 methods must bewritten for \code{\link{as.double}}. It is identical to\code{as.double} (and \code{as.real}).\code{is.numeric} is generic: you can write methods to handlespecific classes of objects, see \link{InternalMethods}. It is\strong{not} the same as \code{\link{is.double}}. Factors are handledby the default method, and there are methods for classes\code{"\link{Date}"} and \code{"\link{POSIXt}"} (in all three casesthe result is false). Methods for \code{is.numeric} should onlyreturn true if the base type of the class is \code{double} or\code{integer} \emph{and} values can reasonably be regarded asnumeric (e.g. arithmetic on them makes sense).}\value{for \code{numeric} and \code{as.numeric} see \code{\link{double}}.The default method for \code{is.numeric} returns \code{TRUE}if its argument is of \link{mode} \code{"numeric"}(\link{type} \code{"double"} or type \code{"integer"}) and not afactor, and \code{FALSE} otherwise. That is,\code{is.integer(x) || is.double(x)}, or\code{(mode(x) == "numeric") && !is.factor(x)}.}\section{S4 methods}{\code{as.numeric} and \code{is.numeric} are internally S4 generic andso 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}.}%% keep next the same in double.Rd & numeric.Rd\section{Note on names}{It is a historical anomaly that \R has three names for itsfloating-point vectors, \code{\link{double}}, \code{\link{numeric}}and \code{\link{real}}.\code{double} is the name of the \link{type}.\code{numeric} is the name of the \link{mode} and also of the implicit\link{class}. As an S4 formal class, use \code{"numeric"} (there wasa formal class \code{"double"} prior to \R 2.7.0).\code{real} is deprecated and should not be used in new code.The potential confusion is that \R has used \emph{\link{mode}}\code{"numeric"} to mean \sQuote{double or integer}, which conflictswith the S4 usage. Thus \code{is.numeric} tests the mode, not theclass, but \code{as.numeric} (which is identical to \code{as.double})coerces to the class.}\seealso{\code{\link{double}}, \code{\link{integer}}, \code{\link{storage.mode}}.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth \& Brooks/Cole.}\examples{as.numeric(c("-.1"," 2.7 ","B")) # (-0.1, 2.7, NA) + warningas.numeric(factor(5:10))}\keyword{classes}\keyword{attribute}