| data_rename | R Documentation |
Safe and intuitive functions to rename variables or rows in
data frames. data_rename() will rename column names, i.e. it facilitates
renaming variables. data_rename_rows() is a convenient shortcut
to add or rename row names of a data frame, but unlike row.names(), its
input and output is a data frame, thus, integrating smoothly into a
possible pipe-workflow.
data_rename(data, select = NULL, replacement = NULL, ...)
data_rename_rows(data, rows = NULL)
data |
A data frame. |
select |
Variables that will be included when performing the required tasks. Can be either
If |
replacement |
Character vector. Can be one of the following:
If |
... |
Other arguments passed to or from other functions. |
rows |
Vector of row names. |
select can also be a named character vector. In this case, the names are
used to rename the columns in the output data frame. If you have a named
list, use unlist() to convert it to a named vector. See 'Examples'.
A modified data frame.
Add a prefix or suffix to column names: data_addprefix(), data_addsuffix()
Functions to reorder or remove columns: data_reorder(), data_relocate(),
data_remove()
Functions to reshape, pivot or rotate data frames: data_to_long(),
data_to_wide(), data_rotate()
Functions to recode data: rescale(), reverse(), categorize(),
recode_values(), slide()
Functions to standardize, normalize, rank-transform: center(), standardize(),
normalize(), ranktransform(), winsorize()
Split and merge data frames: data_partition(), data_merge()
Functions to find or select columns: data_select(), extract_column_names()
Functions to filter rows: data_match(), data_filter()
# Rename columns
head(data_rename(iris, "Sepal.Length", "length"))
# Use named vector to rename
head(data_rename(iris, c(length = "Sepal.Length", width = "Sepal.Width")))
# Change all
head(data_rename(iris, replacement = paste0("Var", 1:5)))
# Use glue-styled patterns
head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "formerly_{col}"))
head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "{col}_is_column_{n}"))
head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "new_{letter}"))
# User-defined glue-styled patterns from objects in environment
x <- c("hi", "there", "!")
head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.