data_addprefix {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_addprefix()
or data_addsuffix()
add prefixes
or suffixes to column names. 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_addprefix(
data,
pattern,
select = NULL,
exclude = NULL,
ignore_case = FALSE,
regex = FALSE,
verbose = TRUE,
...
)
data_addsuffix(
data,
pattern,
select = NULL,
exclude = NULL,
ignore_case = FALSE,
regex = FALSE,
verbose = TRUE,
...
)
data_rename(
data,
pattern = NULL,
replacement = NULL,
safe = TRUE,
verbose = TRUE,
...
)
data_rename_rows(data, rows = NULL)
Arguments
data |
A data frame, or an object that can be coerced to a data frame. |
pattern |
Character vector. For |
select |
Variables that will be included when performing the required tasks. Can be either
If |
exclude |
See |
ignore_case |
Logical, if |
regex |
Logical, if |
verbose |
Toggle warnings and messages. |
... |
Other arguments passed to or from other functions. |
replacement |
Character vector. Indicates the new name of the columns
selected in |
safe |
Do not throw error if for instance the variable to be renamed/removed doesn't exist. |
rows |
Vector of row names. |
Value
A modified data frame.
See Also
Functions to rename stuff:
data_rename()
,data_rename_rows()
,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
# Add prefix / suffix to all columns
head(data_addprefix(iris, "NEW_"))
head(data_addsuffix(iris, "_OLD"))
# Rename columns
head(data_rename(iris, "Sepal.Length", "length"))
# data_rename(iris, "FakeCol", "length", safe=FALSE) # This fails
head(data_rename(iris, "FakeCol", "length")) # This doesn't
head(data_rename(iris, c("Sepal.Length", "Sepal.Width"), c("length", "width")))
# Reset names
head(data_rename(iris, NULL))
# Change all
head(data_rename(iris, replacement = paste0("Var", 1:5)))