rename_by_list: Rename variables based on a list

View source: R/rename_by_list.R

rename_by_listR Documentation

Rename variables based on a list

Description

Rename variables based on a list

Usage

rename_by_list(data, file = NULL, to_from = NULL, to = NULL, from = NULL)

Arguments

data

A data frame with variables to be renamed

file

A filename of an Excel file containing at least two columns (variables) for renaming. Or a data frame with two columns.

to_from

When a filename or a data.frame is provided, a named character with the names of the target and source variable names (e.g., c("to" = "from")). When no filename is provided, to_from must be a vector with named variable names c("to1" = "from1", "to2" = "from2")).

to

When a filename or a data.frame is provided, the name of the column with the target variable names. When no filename is provided, to must a vector with target variable names.

from

When a filename or a data.frame is provided, the name of the column with the source variable names. When no filename is provided, from must a vector with source variable names.

Value

A data frame

Examples

dat <- data.frame(A = NA, B = NA, C = NA, D = NA)
rename_by_list(dat, to = c("albert", "bea"), from = c("A", "B"))
rename_by_list(dat, to_from = c("carl" = "C", "daniel" = "D"))
dic <- data.frame(old = c("A", "B"), new = c("albert", "bea"))
rename_by_list(dat, dic, to_from = c("new" = "old"))
rename_by_list(dat, dic, to = "new", from = "old")
## Not run: 
rename_by_list(dat, "rename_list,xlsx", to_from = c("new" = "old"))
rename_by_list(dat, "rename_list,xlsx", to = "new", from = "old")

## End(Not run)

jazznbass/scaledic documentation built on July 19, 2023, 12:50 a.m.