safe_rename | R Documentation |
Replaces specified column names with user-defined vector of new column name(s). This operation is done "safely" because it specifically matches each 'bad' name with its corresponding 'good' name and thus minimizes the risk of accidentally replacing the wrong column name.
safe_rename(data = NULL, bad_names = NULL, good_names = NULL)
data |
(dataframe or dataframe-like) object with column names that match the values passed to the |
bad_names |
(character) vector of column names to replace in original data object. Order does not need to match data column order but must match the |
good_names |
(character) vector of column names to use as replacements for data object. Order does not need to match data column order but must match the |
(dataframe or dataframe-like) with renamed columns
# Make a dataframe to demonstrate
df <- data.frame("first" = 1:3, "middle" = 4:6, "second" = 7:9)
# Invoke the function
safe_rename(data = df, bad_names = c("second", "middle"),
good_names = c("third", "second"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.