EVOLUTION-MANAGER
Edit File: extract.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: Extract a character column into multiple columns using...</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 extract {tidyr}"><tr><td>extract {tidyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract a character column into multiple columns using regular expression groups</h2> <h3>Description</h3> <p>Given a regular expression with capturing groups, <code>extract()</code> turns each group into a new column. If the groups don't match, or the input is NA, the output will be NA. </p> <h3>Usage</h3> <pre> extract( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>A data frame.</p> </td></tr> <tr valign="top"><td><code>col</code></td> <td> <p>Column name or position. This is passed to <code><a href="../../tidyselect/html/vars_pull.html">tidyselect::vars_pull()</a></code>. </p> <p>This argument is passed by expression and supports <a href="../../rlang/html/nse-force.html">quasiquotation</a> (you can unquote column names or column positions).</p> </td></tr> <tr valign="top"><td><code>into</code></td> <td> <p>Names of new variables to create as character vector. Use <code>NA</code> to omit the variable in the output.</p> </td></tr> <tr valign="top"><td><code>regex</code></td> <td> <p>a regular expression used to extract the desired values. There should be one group (defined by <code style="white-space: pre;">()</code>) for each element of <code>into</code>.</p> </td></tr> <tr valign="top"><td><code>remove</code></td> <td> <p>If <code>TRUE</code>, remove input column from output data frame.</p> </td></tr> <tr valign="top"><td><code>convert</code></td> <td> <p>If <code>TRUE</code>, will run <code><a href="../../utils/html/type.convert.html">type.convert()</a></code> with <code>as.is = TRUE</code> on new columns. This is useful if the component columns are integer, numeric or logical. </p> <p>NB: this will cause string <code>"NA"</code>s to be converted to <code>NA</code>s.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments passed on to methods.</p> </td></tr> </table> <h3>See Also</h3> <p><code><a href="separate.html">separate()</a></code> to split up by a separator. </p> <h3>Examples</h3> <pre> df <- data.frame(x = c(NA, "a-b", "a-d", "b-c", "d-e")) df %>% extract(x, "A") df %>% extract(x, c("A", "B"), "([[:alnum:]]+)-([[:alnum:]]+)") # If no match, NA: df %>% extract(x, c("A", "B"), "([a-d]+)-([a-d]+)") </pre> <hr /><div style="text-align: center;">[Package <em>tidyr</em> version 1.1.2 <a href="00Index.html">Index</a>]</div> </body></html>