EVOLUTION-MANAGER
Edit File: integer.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Integer Vectors</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for integer {base}"><tr><td>integer {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Integer Vectors</h2> <h3>Description</h3> <p>Creates or tests for objects of type <code>"integer"</code>. </p> <h3>Usage</h3> <pre> integer(length = 0) as.integer(x, ...) is.integer(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>length</code></td> <td> <p>A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error.</p> </td></tr> <tr valign="top"><td><code>x</code></td> <td> <p>object to be coerced or tested.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further arguments passed to or from other methods.</p> </td></tr> </table> <h3>Details</h3> <p>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. </p> <p>Note that current implementations of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> use 32-bit integers for integer vectors, so the range of representable integers is restricted to about <i>+/-2*10^9</i>: <code><a href="double.html">double</a></code>s can hold much larger integers exactly. </p> <h3>Value</h3> <p><code>integer</code> creates a integer vector of the specified length. Each element of the vector is equal to <code>0</code>. </p> <p><code>as.integer</code> attempts to coerce its argument to be of integer type. The answer will be <code>NA</code> unless the coercion succeeds. Real values larger in modulus than the largest integer are coerced to <code>NA</code> (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)</code> equals <code><a href="Round.html">trunc</a>(x)</code> there), and imaginary parts of complex numbers are discarded (with a warning). Character strings containing optional whitespace followed by either a decimal representation or a hexadecimal representation (starting with <code>0x</code> or <code>0X</code>) can be converted, as well as any allowed by the platform for real numbers. Like <code><a href="vector.html">as.vector</a></code> it strips attributes including names. (To ensure that an object <code>x</code> is of integer type without stripping attributes, use <code><a href="mode.html">storage.mode</a>(x) <- "integer"</code>.) </p> <p><code>is.integer</code> returns <code>TRUE</code> or <code>FALSE</code> depending on whether its argument is of integer <a href="typeof.html">type</a> or not, unless it is a factor when it returns <code>FALSE</code>. </p> <h3>Note</h3> <p><code>is.integer(x)</code> does <b>not</b> test if <code>x</code> contains integer numbers! For that, use <code><a href="Round.html">round</a></code>, as in the function <code>is.wholenumber(x)</code> in the examples. </p> <h3>References</h3> <p>Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) <em>The New S Language</em>. Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="numeric.html">numeric</a></code>, <code><a href="mode.html">storage.mode</a></code>. </p> <p><code><a href="Round.html">round</a></code> (and <code>ceiling</code> and <code>floor</code> on that help page) to convert to integral values. </p> <h3>Examples</h3> <pre> ## as.integer() truncates: x <- pi * c(-1:1, 10) as.integer(x) is.integer(1) # is FALSE ! is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol is.wholenumber(1) # is TRUE (x <- seq(1, 5, by = 0.5) ) is.wholenumber( x ) #--> TRUE FALSE TRUE ... </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>