The R Project SVN R

Rev

Rev 25376 | Rev 34293 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 r 1
\name{integer}
880 hornik 2
\alias{integer}
3
\alias{as.integer}
3279 pd 4
\alias{as.integer.default}
880 hornik 5
\alias{is.integer}
7247 hornik 6
\title{Integer Vectors}
7
\description{
8
  Creates or tests for objects of type \code{"integer"}.
9
}
2 r 10
\usage{
880 hornik 11
integer(length = 0)
10525 ripley 12
as.integer(x, \dots)
2 r 13
is.integer(x)
14
}
15518 ripley 15
\arguments{
16
  \item{length}{desired length.}
17
  \item{x}{object to be coerced or tested.}
18
  \item{\dots}{further arguments passed to or from other methods.}
19
}
2 r 20
\value{
7247 hornik 21
  \code{integer} creates a integer vector of the specified length.
880 hornik 22
  Each element of the vector is equal to \code{0}.
23
  Integer vectors exist so that data can be passed to C or Fortran code
24
  which expects them.
2 r 25
 
880 hornik 26
  \code{as.integer} attempts to coerce its argument to be of integer
14074 ripley 27
  type. The answer will be \code{NA} unless the coercion succeeds.
28
  Real values larger in modulus than the largest integer are coerced to
29
  \code{NA} (unlike S which gives the most extreme integer of the same sign).
22694 ripley 30
  Non-integral numeric values are truncated towards zero (i.e.,
31
  \code{as.integer(x)} equals \code{\link{trunc}(x)} there), and
32
  imaginary parts of complex numbers are discarded (with a warning).
24601 ripley 33
  Like \code{\link{as.vector}} it strips attributes including names.
2 r 34
 
880 hornik 35
  \code{is.integer} returns \code{TRUE} or \code{FALSE} depending on
22694 ripley 36
  whether its argument is of integer type or not.
23358 ripley 37
  \code{is.integer} is generic: you can write methods to handle
27625 ripley 38
  specific classes of objects, see \link{InternalMethods}.
25376 ripley 39
  Note that factors are true for \code{is.integer} but false for
40
  \code{\link{is.numeric}}.
2 r 41
}
24300 ripley 42
\references{
43
  Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
44
  \emph{The New S Language}.
45
  Wadsworth \& Brooks/Cole.
46
}
22215 ripley 47
\seealso{
48
  \code{\link{round}} (and \code{ceiling} and \code{floor} on that help
49
  page) to convert to integral values.
50
}
22694 ripley 51
\examples{
52
  ## as.integer() truncates:
53
  x <- pi * c(-1:1,10)
54
  as.integer(x)
55
}
286 maechler 56
\keyword{classes}