integer
.
integer(length=0) is.integer(x) as.integer(x)
integer
returns a simple object of storage mode
"integer"
, and the length specified.
is.integer
returns
TRUE
if
x
is an object of storage mode
"integer"
, and
FALSE
otherwise.
as.integer
returns
x
if
x
is a simple object of storage mode
"integer"
.
Otherwise, it returns an integer object of the same length as
x
and with data resulting
from coercing the elements of
x
to storage mode
"integer"
.
The numbers are truncated (moved to the closest integer the original
number that is towards zero).
Attributes are deleted.
Both
as.integer
and
is.integer
are generic functions.
There is a
"factor"
method for
is.integer
.
Note the difference between coercing to a simple object
of storage mode
"integer"
and setting the storage mode attribute:
storage.mode(myobject) <- "integer"
This changes the storage mode of
myobject
but leaves all other attributes unchanged
(so a matrix stays a matrix). The value of
as.integer(myobject)
has no attributes.
The
bits.per.integer
function provides a way to
determine the number of bits in an integer literal for a given version of
S-PLUS.
In most S-PLUS expressions it is not
necessary to explicitly ensure that data are of a particular storage
mode.
For example,
a numeric subscript vector need not be integer;
it will be coerced to
integer as needed.
When testing for data suitable for arithmetic, for example, it is better to
use
is.numeric(x)
,
which will return
TRUE
for any numeric object.
z <- integer(length(letters)) # integer object same length as letters # Example of coercion in a fictional Fortran call # .Fortran("mysub",as.integer(xm))