Skip to contents

Harmonize surveys with crosswalk tables.

Usage

crosswalk_surveys(
  crosswalk_table,
  survey_list = NULL,
  survey_path = NULL,
  import_path = NULL,
  na_values = NULL
)

crosswalk(survey_list, crosswalk_table, na_values = NULL)

Arguments

crosswalk_table

A table created with crosswalk_table_create, or a data frame with at least the following columns: var_name_orig, var_name_target, for harmonizing the variable names. If val_label_orig, val_label_target are present, the value labels will be harmonized, too. If var_numeric_orig, var_numeric_target are present, the numeric codes of the variable will be harmonized. If class_target is present, then the class of the variable will be harmonized to any of factor, numeric or character using as_factor, as_numeric, or as_character.

survey_list

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

na_values

A named vector of na_values, the observations that are defined to be treated as missing in the SPSS-style coding. Defaults to NULL.

Value

crosswalk will return a data frame, and crosswalk_surveys a list of data frames, where the variable names, and optionally the variable labels, and the missing value range is harmonized (the same names, labels, codes are used.)

Details

Harmonize a survey or a list of surveys with the help of a crosswalk table. You can create the crosswalk table with crosswalk_table_create, or manually create a crosswalk table as a data frame including at least the following columns: id for identifying a survey, var_name_orig for the original variable name and var_name_target for the new (target) variable name. Optionally you can harmonize the value labels, the numeric codes, and the special missing labels, too.

Examples

# \donttest{
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), 
  save_to_rds = FALSE)
#> Error in read_surveys(file.path(examples_dir, survey_list), save_to_rds = FALSE): unused argument (save_to_rds = FALSE)

## Compare with documentation:
documented_surveys <- metadata_surveys_create(example_surveys)
#> Error in metadata_surveys_create(example_surveys): could not find function "metadata_surveys_create"
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"),
                                          ]
#> Error in eval(expr, envir, enclos): object 'documented_surveys' not found
crosswalk_table <- crosswalk_table_create ( metadata = documented_surveys )
#> Error in inherits(metadata, "data.frame"): object 'documented_surveys' not found
# }