crosswalk_surveys: Crosswalk surveys

View source: R/crosswalk.R

crosswalk_surveysR Documentation

Crosswalk surveys

Description

Harmonize surveys with crosswalk tables.

Usage

crosswalk_surveys(
  crosswalk_table,
  survey_list = NULL,
  survey_paths = 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.

survey_paths

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

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.

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.

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.)

See Also

Other harmonization functions: collect_val_labels(), crosswalk_table_create(), harmonize_na_values(), harmonize_survey_values(), harmonize_values(), harmonize_var_names(), label_normalize()

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), 
  save_to_rds = FALSE)

## Compare with documentation:
documented_surveys <- metadata_surveys_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 )


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