rename_lookup | R Documentation |
This is useful when you have a vector of old names and a vector of new names, or columns in a data frame.
rename_lookup(x, old, new, warn = FALSE)
x |
An object with names. |
old |
Character vector. Existing names will be found using
|
new |
Character vector. A vector of new names to replace corresponding
elements in |
warn |
Logical. Warn if any names are unmatched? |
Unmatched names are left unchanged.
x
renamed according to names(x) <- new[match(names(x), old)]
.
df <- data.frame(
old = c("One", "Two", "Three"),
new = c("New", "Newer", "Newest")
)
vec <- c("One" = 1, "Two" = 2, "Three" = 3, "Four" = 4)
vec |> rename_lookup(df$old, df$new)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.