integer {base} | R Documentation |

## Integer Vectors

### Description

Creates or tests for objects of type `"integer"`

.

### Usage

integer(length = 0)
as.integer(x, ...)
is.integer(x)

### Arguments

`length` |
desired length. |

`x` |
object to be coerced or tested. |

`...` |
further arguments passed to or from other methods. |

### Details

Integer vectors exist so that data can be passed to C or Fortran code
which expects them, and so that small integer data can be represented
exactly and compactly.

Note that on almost all implementations of **R** the range of
representable integers is restricted to about
*+/-2*10^9*: `double`

s can hold
much larger integers exactly.

### Value

`integer`

creates a integer vector of the specified length.
Each element of the vector is equal to `0`

.

`as.integer`

attempts to coerce its argument to be of integer
type. The answer will be `NA`

unless the coercion succeeds.
Real values larger in modulus than the largest integer are coerced to
`NA`

(unlike S which gives the most extreme integer of the same sign).
Non-integral numeric values are truncated towards zero (i.e.,
`as.integer(x)`

equals `trunc(x)`

there), and
imaginary parts of complex numbers are discarded (with a warning).
Character strings containing either a decimal representation or a
hexadecimal representation (starting with `0x`

or `0X`

) can
be converted, as well as any allowed by the platform for real numbers.
Like `as.vector`

it strips attributes including names.
(To ensure that an object is of integer type without stripping
attributes, use `storage.mode`

.)

`is.integer`

returns `TRUE`

or `FALSE`

depending on
whether its argument is of integer type or not, unless it is a
factor when it returns `FALSE`

.

### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
*The New S Language*.
Wadsworth & Brooks/Cole.

### See Also

`numeric`

, `storage.mode`

.

`round`

(and `ceiling`

and `floor`

on that help
page) to convert to integral values.

### Examples

## as.integer() truncates:
x <- pi * c(-1:1,10)
as.integer(x)

[Package

*base* version 2.5.0

Index]