EVOLUTION-MANAGER
Edit File: set_names.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: Set names of a vector</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 set_names {rlang}"><tr><td>set_names {rlang}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Set names of a vector</h2> <h3>Description</h3> <p>This is equivalent to <code><a href="../../stats/html/setNames.html">stats::setNames()</a></code>, with more features and stricter argument checking. </p> <h3>Usage</h3> <pre> set_names(x, nm = x, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Vector to name.</p> </td></tr> <tr valign="top"><td><code>nm, ...</code></td> <td> <p>Vector of names, the same length as <code>x</code>. If length 1, <code>nm</code> is recycled to the length of <code>x</code> following the recycling rules of the tidyverse.. </p> <p>You can specify names in the following ways: </p> <ul> <li><p> If not supplied, <code>x</code> will be named to <code>as.character(x)</code>. </p> </li> <li><p> If <code>x</code> already has names, you can provide a function or formula to transform the existing names. In that case, <code>...</code> is passed to the function. </p> </li> <li><p> Otherwise if <code>...</code> is supplied, <code>x</code> is named to <code>c(nm, ...)</code>. </p> </li> <li><p> If <code>nm</code> is <code>NULL</code>, the names are removed (if present). </p> </li></ul> </td></tr> </table> <h3>Life cycle</h3> <p><code>set_names()</code> is stable and exported in purrr. </p> <h3>Examples</h3> <pre> set_names(1:4, c("a", "b", "c", "d")) set_names(1:4, letters[1:4]) set_names(1:4, "a", "b", "c", "d") # If the second argument is ommitted a vector is named with itself set_names(letters[1:5]) # Alternatively you can supply a function set_names(1:10, ~ letters[seq_along(.)]) set_names(head(mtcars), toupper) # If the input vector is unnamed, it is first named after itself # before the function is applied: set_names(letters, toupper) # `...` is passed to the function: set_names(head(mtcars), paste0, "_foo") # If length 1, the second argument is recycled to the length of the first: set_names(1:3, "foo") set_names(list(), "") </pre> <hr /><div style="text-align: center;">[Package <em>rlang</em> version 1.0.6 <a href="00Index.html">Index</a>]</div> </body></html>