harmonize_survey_variables: Harmonize survey variables

View source: R/harmonize_survey_variables.R

harmonize_survey_variablesR Documentation

Harmonize survey variables

Description

Similar to subset_surveys, but will not only remove the variables that cannot be harmonized, but also renames the variables that are kept.

Usage

harmonize_survey_variables(
  crosswalk_table,
  subset_name = "subset",
  survey_list = NULL,
  survey_paths = NULL,
  import_path = NULL,
  export_path = NULL
)

Arguments

crosswalk_table

A crosswalk table created by crosswalk_table_create or a manually created crosstable including at least filename, var_name_orig, var_name_target and optionally var_label_orig and var_label_target. This parameter is optional and defaults to NULL.

subset_name

An identifier for the survey subset.

survey_list

A list of surveys imported with read_surveys. If set to NULL, the survey_path should give full path to the surveys.

survey_paths

A vector of full file paths to the surveys to subset.

Value

A list of surveys or save individual rds files on the export_path.

Examples

{
examples_dir <- system.file("examples", package = "retroharmonize")
survey_list  <- dir(examples_dir)[grepl("\\.rds", dir(examples_dir))]
example_surveys <- read_surveys(
  file.path( examples_dir, survey_list), 
  export_path = NULL)

documented_surveys <- metadata_create(example_surveys)
documented_surveys <- documented_surveys[
   documented_surveys$var_name_orig %in% c( "rowid", "isocntry", "w1", "qd3_4",
   "qd3_8" , "qd7.4", "qd7.8", "qd6.4", "qd6.8"),
   ]
crosswalk_table    <- crosswalk_table_create ( metadata = documented_surveys )

freedom_table <- crosswalk_table[
                     which(crosswalk_table$var_name_target %in% c("rowid", "freedom")),
                     ]

harmonize_survey_variables(crosswalk_table = freedom_table,
                           subset_name     = 'freedom',
                           survey_list     = example_surveys )

}

antaldaniel/retroharmonize documentation built on Dec. 11, 2023, 10:49 p.m.