View source: R/harmonize_var_names.R
| harmonize_var_names | R Documentation |
'harmonize_var_names()' renames variables across multiple surveys to a shared harmonized naming scheme.
The harmonization rules are defined in a metadata table, typically created with [metadata_create()].
harmonize_var_names(
survey_list,
metadata,
old = "var_name_orig",
new = "var_name_suggested",
rowids = TRUE
)
survey_list |
A list of survey objects, typically imported with [read_surveys()]. |
metadata |
A metadata table containing harmonization rules. Typically created with [metadata_create()] and combined across surveys. |
old |
Name of the column in 'metadata' containing the original variable names. |
new |
Name of the column in 'metadata' containing the harmonized variable names. |
rowids |
Logical. Should original 'rowid' variables be renamed to '"uniqid"'? |
Harmonize variable names in a list of survey objects using a metadata crosswalk table.
The function can also be used for survey subsetting workflows. If 'metadata' contains only a subset of variables for a survey, only those variables are retained in the harmonized output.
A list of surveys with harmonized variable names.
[metadata_create()], [crosswalk()]
Other harmonization functions:
collect_val_labels(),
crosswalk_surveys(),
harmonize_na_values(),
harmonize_survey_values(),
harmonize_values(),
is.crosswalk_table(),
label_normalize()
examples_dir <- system.file(
"examples",
package = "retroharmonize"
)
survey_files <- dir(
examples_dir,
pattern = "\\.rds$"
)
example_surveys <- read_surveys(
file.path(examples_dir, survey_files)
)
metadata <- metadata_create(
example_surveys
)
metadata$var_name_suggested <-
label_normalize(metadata$var_name)
metadata$var_name_suggested[
metadata$label_orig == "age_education"
] <- "age_education"
harmonized_surveys <- harmonize_var_names(
survey_list = example_surveys,
metadata = metadata
)
harmonized_surveys[[1]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.