EVOLUTION-MANAGER
Edit File: vec_split.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: Split a vector into 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_split {vctrs}"><tr><td>vec_split {vctrs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Split a vector into groups</h2> <h3>Description</h3> <p>This is a generalisation of <code><a href="../../base/html/split.html">split()</a></code> that can split by any type of vector, not just factors. Instead of returning the keys in the character names, the are returned in a separate parallel vector. </p> <h3>Usage</h3> <pre> vec_split(x, by) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Vector to divide into groups.</p> </td></tr> <tr valign="top"><td><code>by</code></td> <td> <p>Vector whose unique values defines the groups.</p> </td></tr> </table> <h3>Value</h3> <p>A data frame with two columns and size equal to <code>vec_size(vec_unique(by))</code>. The <code>key</code> column has the same type as <code>by</code>, and the <code>val</code> column is a list containing elements of type <code>vec_ptype(x)</code>. </p> <p>Note 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_group.html">vec_group_loc()</a></code> </p> </li> <li> <p><code><a href="vec_chop.html">vec_chop()</a></code> </p> </li></ul> <h3>Examples</h3> <pre> vec_split(mtcars$cyl, mtcars$vs) vec_split(mtcars$cyl, mtcars[c("vs", "am")]) if (require("tibble")) { as_tibble(vec_split(mtcars$cyl, mtcars[c("vs", "am")])) as_tibble(vec_split(mtcars, 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>