View source: R/harmonize_var_names.R
| harmonize_var_names | R Documentation |
Rename and optionally subset variables across survey datasets using a metadata crosswalk table.
harmonize_var_names(
survey_list,
metadata,
old = "var_name_orig",
new = "var_name_suggested",
rowids = TRUE
)
survey_list |
A list of objects of class [survey()] or [survey_df()], typically imported with [read_surveys()]. |
metadata |
A data frame containing harmonization rules, typically derived from [metadata_create()]. |
old |
Name of the metadata column containing the original variable names. |
new |
Name of the metadata column containing the harmonized variable names. |
rowids |
Reserved for backward compatibility. Row identifier variables are renamed only when explicitly specified in the metadata table. |
Harmonization rules are matched to surveys by filename. Only variables included in the metadata table are retained. The original variable order, observation values, variable attributes and survey-level metadata are preserved.
Identical repeated mappings are accepted. Contradictory mappings, duplicate target names and missing or empty target names are rejected.
If metadata are unavailable for a survey, a warning is issued and a survey with no variables is returned.
A list of surveys with harmonized variable names.
[metadata_create()], [crosswalk()]
Other harmonization functions:
collect_val_labels(),
create_codebook(),
crosswalk_surveys(),
harmonize_na_values(),
harmonize_survey_values(),
harmonize_values(),
is.crosswalk_table(),
label_normalize()
examples_dir <- system.file(
"examples",
package = "retroharmonize"
)
survey_files <- list.files(
examples_dir,
pattern = "\\.rds$",
full.names = TRUE
)
example_surveys <- read_surveys(survey_files)
metadata <- metadata_create(example_surveys)
metadata$var_name_suggested <- metadata$var_name_orig
metadata$var_name_suggested[
metadata$var_name_orig == "rowid"
] <- "uniqid"
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.