EVOLUTION-MANAGER
Edit File: length.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: Length of an Object</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 length {base}"><tr><td>length {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Length of an Object</h2> <h3>Description</h3> <p>Get or set the length of vectors (including lists) and factors, and of any other <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object for which a method has been defined. </p> <h3>Usage</h3> <pre> length(x) length(x) <- value </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object. For replacement, a vector or factor.</p> </td></tr> <tr valign="top"><td><code>value</code></td> <td> <p>a non-negative integer or double (which will be rounded down).</p> </td></tr> </table> <h3>Details</h3> <p>Both functions are generic: you can write methods to handle specific classes of objects, see <a href="InternalMethods.html">InternalMethods</a>. <code>length<-</code> has a <code>"factor"</code> method. </p> <p>The replacement form can be used to reset the length of a vector. If a vector is shortened, extra values are discarded and when a vector is lengthened, it is padded out to its new length with <code><a href="NA.html">NA</a></code>s (<code>nul</code> for raw vectors). </p> <p>Both are <a href="Primitive.html">primitive</a> functions. </p> <h3>Value</h3> <p>The default method for <code>length</code> currently returns a non-negative <code><a href="integer.html">integer</a></code> of length 1, except for vectors of more than <i>2^31 - 1</i> elements, when it returns a double. </p> <p>For vectors (including lists) and factors the length is the number of elements. For an environment it is the number of objects in the environment, and <code>NULL</code> has length 0. For expressions and pairlists (including <a href="is.language.html">language objects</a> and dotlists) it is the length of the pairlist chain. All other objects (including functions) have length one: note that for functions this differs from S. </p> <p>The replacement form removes all the attributes of <code>x</code> except its names, which are adjusted (and if necessary extended by <code>""</code>). </p> <h3>Warning</h3> <p>Package authors have written methods that return a result of length other than one (<a href="https://CRAN.R-project.org/package=Formula"><span class="pkg">Formula</span></a>) and that return a vector of type <code><a href="double.html">double</a></code> (<a href="https://CRAN.R-project.org/package=Matrix"><span class="pkg">Matrix</span></a>), even with non-integer values (earlier versions of <a href="https://CRAN.R-project.org/package=sets"><span class="pkg">sets</span></a>). Where a single double value is returned that can be represented as an integer it is returned as a length-one integer vector. </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>nchar</code> for counting the number of characters in character vectors, <code><a href="lengths.html">lengths</a></code> for getting the length of every element in a list. </p> <h3>Examples</h3> <pre> length(diag(4)) # = 16 (4 x 4) length(options()) # 12 or more length(y ~ x1 + x2 + x3) # 3 length(expression(x, {y <- x^2; y+2}, x^y)) # 3 ## from example(warpbreaks) require(stats) fm1 <- lm(breaks ~ wool * tension, data = warpbreaks) length(fm1$call) # 3, lm() and two arguments. length(formula(fm1)) # 3, ~ lhs rhs </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>