EVOLUTION-MANAGER
Edit File: vec_group.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: Identify groups</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 vec_group {vctrs}"><tr><td>vec_group {vctrs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Identify groups</h2> <h3>Description</h3> <p><a href="https://lifecycle.r-lib.org/articles/stages.html#experimental"><img src="../help/figures/lifecycle-experimental.svg" alt='[Experimental]' /></a> </p> <ul> <li> <p><code>vec_group_id()</code> returns an identifier for the group that each element of <code>x</code> falls in, constructed in the order that they appear. The number of groups is also returned as an attribute, <code>n</code>. </p> </li> <li> <p><code>vec_group_loc()</code> returns a data frame containing a <code>key</code> column with the unique groups, and a <code>loc</code> column with the locations of each group in <code>x</code>. </p> </li> <li> <p><code>vec_group_rle()</code> locates groups in <code>x</code> and returns them run length encoded in the order that they appear. The return value is a rcrd object with fields for the <code>group</code> identifiers and the run <code>length</code> of the corresponding group. The number of groups is also returned as an attribute, <code>n</code>. </p> </li></ul> <h3>Usage</h3> <pre> vec_group_id(x) vec_group_loc(x) vec_group_rle(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A vector</p> </td></tr> </table> <h3>Value</h3> <ul> <li> <p><code>vec_group_id()</code>: An integer vector with the same size as <code>x</code>. </p> </li> <li> <p><code>vec_group_loc()</code>: A two column data frame with size equal to <code>vec_size(vec_unique(x))</code>. </p> <ul> <li><p> A <code>key</code> column of type <code>vec_ptype(x)</code> </p> </li> <li><p> A <code>loc</code> column of type list, with elements of type integer. </p> </li></ul> </li> <li> <p><code>vec_group_rle()</code>: A <code>vctrs_group_rle</code> rcrd object with two integer vector fields: <code>group</code> and <code>length</code>. </p> </li></ul> <p>Note that when using <code>vec_group_loc()</code> for complex types, the default <code>data.frame</code> print method will be suboptimal, and you will want to coerce into a tibble to better understand the output. </p> <h3>Dependencies</h3> <ul> <li> <p><code><a href="vec_proxy_equal.html">vec_proxy_equal()</a></code> </p> </li></ul> <h3>Examples</h3> <pre> purrr <- c("p", "u", "r", "r", "r") vec_group_id(purrr) vec_group_rle(purrr) groups <- mtcars[c("vs", "am")] vec_group_id(groups) group_rle <- vec_group_rle(groups) group_rle # Access fields with `field()` field(group_rle, "group") field(group_rle, "length") # `vec_group_id()` is equivalent to vec_match(groups, vec_unique(groups)) vec_group_loc(mtcars$vs) vec_group_loc(mtcars[c("vs", "am")]) if (require("tibble")) { as_tibble(vec_group_loc(mtcars[c("vs", "am")])) } </pre> <hr /><div style="text-align: center;">[Package <em>vctrs</em> version 0.5.0 <a href="00Index.html">Index</a>]</div> </body></html>