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_createor a manually created crosstable including at leastfilename,var_name_orig,var_name_targetand optionallyvar_label_origandvar_label_target. This parameter is optional and defaults toNULL.- subset_name
An identifier for the survey subset.
- survey_list
A list of surveys imported with
read_surveys. If set toNULL, thesurvey_pathshould give full path to the surveys.- survey_paths
A vector of full file paths to the surveys to subset.
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 )
}
#> [[1]]
#> # A tibble: 35 × 1
#> rowid
#> <chr>
#> 1 ZA5913_1
#> 2 ZA5913_2
#> 3 ZA5913_3
#> 4 ZA5913_4
#> 5 ZA5913_5
#> 6 ZA5913_6
#> 7 ZA5913_7
#> 8 ZA5913_8
#> 9 ZA5913_9
#> 10 ZA5913_10
#> # … with 25 more rows
#>
#> [[2]]
#> # A tibble: 50 × 1
#> rowid
#> <chr>
#> 1 ZA6863_1
#> 2 ZA6863_2
#> 3 ZA6863_3
#> 4 ZA6863_4
#> 5 ZA6863_5
#> 6 ZA6863_6
#> 7 ZA6863_7
#> 8 ZA6863_8
#> 9 ZA6863_9
#> 10 ZA6863_10
#> # … with 40 more rows
#>
#> [[3]]
#> # A tibble: 45 × 1
#> rowid
#> <chr>
#> 1 ZA7576_1
#> 2 ZA7576_2
#> 3 ZA7576_3
#> 4 ZA7576_4
#> 5 ZA7576_5
#> 6 ZA7576_6
#> 7 ZA7576_7
#> 8 ZA7576_8
#> 9 ZA7576_9
#> 10 ZA7576_10
#> # … with 35 more rows
#>
