data_rename {datawizard} | R Documentation |
Rename columns and variable names
Description
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.
Usage
data_rename(
data,
select = NULL,
replacement = NULL,
safe = TRUE,
verbose = TRUE,
pattern = NULL,
...
)
data_rename_rows(data, rows = NULL)
Arguments
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 |
safe |
Deprecated. Passing unknown column names now always errors. |
verbose |
Toggle warnings. |
pattern |
Deprecated. Use |
... |
Other arguments passed to or from other functions. |
rows |
Vector of row names. |
Details
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'.
Value
A modified data frame.
See Also
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()
Examples
# 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}"))