Numeric Objects

DESCRIPTION:
Creates or tests for objects of mode "numeric".

USAGE:
numeric(length=0)
is.numeric(x)
as.numeric(x)

REQUIRED ARGUMENTS:
x:
any S-PLUS object.

OPTIONAL ARGUMENTS:
length:
integer giving the length of the returned object.

VALUE:
numeric returns a simple object of mode "numeric", and the length specified. The storage mode is "double". If length is greater than 0, the values in this vector are 0.

is.numeric returns TRUE if x has mode "numeric", and FALSE otherwise. Its behavior is unaffected by any attributes of x; for example, x could be a numeric array (in contrast to the behavior of is.vector).

as.numeric returns a vector like x, but with storage mode "double", if x is a simple object of mode "numeric". Otherwise, as.numeric returns a numeric object of the same length as x and with data resulting from coercing the elements of x to mode "numeric".


DETAILS:
The as.numeric function is generic; currently there are no methods defined for it. The is.numeric function is generic in the sense that it depends on the functions is.double, is.single and is.integer, all of which are generic. For example, is.numeric effectively has a method for class "factor" since is.double (and is.integer) have methods for this class. (Factors are not numeric according to is.numeric.)

There is a difference between coercing to a simple object of mode "numeric" and setting the mode attribute: mode(myobject) <- "numeric" This changes the mode of myobject but leaves all other attributes unchanged (so a matrix stays a matrix, e.g.). The value of as.numeric(myobject) has no attributes.


BACKGROUND:
When x is of mode "numeric", the data of x may be stored as integers, or single or double precision floating point numbers and storage.mode(x) will be "integer", "single", or "double", respectively. Normally, all numeric constants that appear in expressions are read with mode numeric and storage mode double. This distinction is only relevant when using the interface to languages like C or Fortran.

The class of simple objects have no attributes. In most S-PLUS expressions it is not necessary to explicitly ensure that data are of a particular mode.


SEE ALSO:
mode , .Fortran , double , single , integer .

EXAMPLES:
z <- numeric(length(zz)) # double object same length as zz
Results are currently computed to single-precision accuracy only.
amp;.Fortran("mydsub",as.double(xm))