\HeaderA{integer}{Integer Vectors}{integer}
\aliasA{as.integer}{integer}{as.integer}
\methaliasA{as.integer.default}{integer}{as.integer.default}
\aliasA{is.integer}{integer}{is.integer}
\methaliasA{is.integer.factor}{integer}{is.integer.factor}
\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}{+/-2*10^9}: \code{\LinkA{double}{double}}s can hold
much larger integers exactly.
\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
heaxadecimal 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.

\code{is.integer} returns \code{TRUE} or \code{FALSE} depending on
whether its argument is of integer \LinkA{type}{type} or not.
\code{is.integer} is generic: you can write methods to handle
specific classes of objects, see \LinkA{InternalMethods}{InternalMethods}.
There is a method for factors which returns \code{FALSE}.
(Prior to \R{} 2.0.0, there was no such method and for most (but not
all) factors \code{is.integer} returned \code{TRUE}.)
\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{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}

