renames: Rename Data Columns from a Codebook

Description Usage Arguments Details Value See Also Examples

View source: R/quest_functions.R

Description

renames renames columns in a data.frame from a codebook. The codebook is assumed to be a list of data.frames containing the old and new column names. See details for how the codebook should be structured. The idea is that the codebook has been imported as an excel workbook with different sets of column renaming information in different workbook sheets. This function is simply a wrapper for plyr::rename.

Usage

1
2
3
4
5
6
7
8
renames(
  data,
  codebook,
  old = 1L,
  new = 2L,
  warn_missing = TRUE,
  warn_duplicated = TRUE
)

Arguments

data

data.frame of data.

codebook

list of data.frames containing the old and new column names.

old

numeric vector or character vector of length 1 specifying the position or name of the column in the codebook data.frames that contains the old column names present in data.

new

numeric vector or character vector of length 1 specifying the position or name of the column in the codebook data.frames that contains the new column names to rename to in data.

warn_missing

logical vector of length 1 specifying whether renames should return a warning if any old names in codebook are not present in data.

warn_duplicated

logical vector of length 1 specifying whether renames should return a warning if the renaming process results in duplicate column names in the return object.

Details

codebook is a list of data.frames where one column refers to the old names and another column refers to the new names. Therefore, each row of the data.frames refers to a column in data. The position or names of the columns in the codebook data.frames that contain the old (i.e., old) and new (i.e., new) data columns must be the same for each data.frame in codebook.

Value

data.frame identical to data except that the old names in codebook have been replaced by the new names in codebook.

See Also

rename

Examples

1
2
3
4
5
code_book <- list(
   data.frame("old" = c("rating","complaints"), "new" = c("RATING","COMPLAINTS")),
   data.frame("old" = c("privileges","learning"), "new" = c("PRIVILEGES","LEARNING"))
)
renames(data = attitude, codebook = code_book, old = "old", new = "new")

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to renames in quest...