EVOLUTION-MANAGER
Edit File: rle.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: Run Length Encoding</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 rle {base}"><tr><td>rle {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Run Length Encoding</h2> <h3>Description</h3> <p>Compute the lengths and values of runs of equal values in a vector – or the reverse operation. </p> <h3>Usage</h3> <pre> rle(x) inverse.rle(x, ...) ## S3 method for class 'rle' print(x, digits = getOption("digits"), prefix = "", ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a vector (atomic, not a list) for <code>rle()</code>; an object of class <code>"rle"</code> for <code>inverse.rle()</code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>further arguments; ignored here.</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>number of significant digits for printing, see <code><a href="print.default.html">print.default</a></code>.</p> </td></tr> <tr valign="top"><td><code>prefix</code></td> <td> <p>character string, prepended to each printed line.</p> </td></tr> </table> <h3>Details</h3> <p>‘vector’ is used in the sense of <code><a href="vector.html">is.vector</a></code>. </p> <p>Missing values are regarded as unequal to the previous value, even if that is also missing. </p> <p><code>inverse.rle()</code> is the inverse function of <code>rle()</code>, reconstructing <code>x</code> from the runs. </p> <h3>Value</h3> <p><code>rle()</code> returns an object of class <code>"rle"</code> which is a list with components: </p> <table summary="R valueblock"> <tr valign="top"><td><code>lengths</code></td> <td> <p>an integer vector containing the length of each run.</p> </td></tr> <tr valign="top"><td><code>values</code></td> <td> <p>a vector of the same length as <code>lengths</code> with the corresponding values.</p> </td></tr> </table> <p><code>inverse.rle()</code> returns an atomic vector. </p> <h3>Examples</h3> <pre> x <- rev(rep(6:10, 1:5)) rle(x) ## lengths [1:5] 5 4 3 2 1 ## values [1:5] 10 9 8 7 6 z <- c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE) rle(z) rle(as.character(z)) print(rle(z), prefix = "..| ") N <- integer(0) stopifnot(x == inverse.rle(rle(x)), identical(N, inverse.rle(rle(N))), z == inverse.rle(rle(z))) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>