\HeaderA{integer}{Integer Vectors}{integer}
\aliasA{as.integer}{integer}{as.integer}
\aliasA{is.integer}{integer}{is.integer}
\keyword{classes}{integer}
\begin{Description}\relax
Creates or tests for objects of type \code{"integer"}.
\end{Description}
\begin{Usage}
\begin{verbatim}
integer(length = 0)
as.integer(x, ...)
is.integer(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
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
\eqn{\pm 2 \times 10^9}{}: \code{\LinkA{double}{double}}s can hold
much larger integers exactly.

\code{as.integer} and \code{is.integer} are \LinkA{primitive}{primitive}, so
positional matching is used and any names of supplied arguments are
ignored.  This may not be true of their methods.
\end{Details}
\begin{Value}
\code{integer} creates a integer vector of the specified length.
Each element of the vector is equal to \code{0}.

\code{as.integer} attempts to coerce its argument to be of integer
type. The answer will be \code{NA} unless the coercion succeeds.
Real values larger in modulus than the largest integer are coerced to
\code{NA} (unlike S which gives the most extreme integer of the same sign).
Non-integral numeric values are truncated towards zero (i.e.,
\code{as.integer(x)} equals \code{\LinkA{trunc}{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 \code{0x} or \code{0X}) can
be converted, as well as any allowed by the platform for real numbers.
Like \code{\LinkA{as.vector}{as.vector}} it strips attributes including names.
(To ensure that an object is of integer type without stripping
attributes, use \code{\LinkA{storage.mode}{storage.mode}}.)

\code{is.integer} returns \code{TRUE} or \code{FALSE} depending on
whether its argument is of integer \LinkA{type}{type} or not, unless it is a
factor when it returns \code{FALSE}.
\end{Value}
\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{numeric}{numeric}}, \code{\LinkA{storage.mode}{storage.mode}}.

\code{\LinkA{round}{round}} (and \code{ceiling} and \code{floor} on that help
page) to convert to integral values.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
  ## as.integer() truncates:
  x <- pi * c(-1:1,10)
  as.integer(x)
\end{ExampleCode}
\end{Examples}

