| renames {quest} | R Documentation |
Rename Data Columns from a Codebook
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
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 |
new |
numeric vector or character vector of length 1 specifying the
position or name of the column in the |
warn_missing |
logical vector of length 1 specifying whether |
warn_duplicated |
logical vector of length 1 specifying whether |
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
Examples
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")