The function harmonizes the variable names of surveys (of class survey) that are imported from an external file as a wave with with read_surveys.

subset_waves(waves, subset_names = NULL)

Arguments

waves

A list of surveys imported with read_surveys.

subset_names

The names of the variables that should be kept from all surveys in the list that contains the wave of surveys. Defaults to NULL in which case it returns all variables without subsetting.

Value

The list of surveys with harmonized variable names.

Details

It is likely that you want to harmonize the variable names with harmonize_var_names first.

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) metadata <- lapply ( X = example_surveys, FUN = metadata_create ) metadata <- do.call(rbind, metadata) metadata$var_name <- label_normalize(metadata$var_name) metadata$var_name[metadata$label_orig == "age education"] <- "age_education" hnw <- harmonize_var_names(waves = example_surveys, metadata = metadata ) subset_waves (hnw, subset_names = c("uniqid", "w1", "age_education"))
#> [[1]] #> # A tibble: 35 x 3 #> uniqid w1 age_education #> <chr> <dbl> <dbl+lbl> #> 1 ZA5913_1 0.875 15 #> 2 ZA5913_2 0.838 15 #> 3 ZA5913_3 1.01 22 #> 4 ZA5913_4 0.476 26 #> 5 ZA5913_5 2.09 17 #> 6 ZA5913_6 1.14 21 #> 7 ZA5913_7 0.787 20 #> 8 ZA5913_8 0.745 21 #> 9 ZA5913_9 0.824 98 [Still studying] #> 10 ZA5913_10 0.720 18 #> # ... with 25 more rows #> #> [[2]] #> # A tibble: 50 x 3 #> uniqid w1 age_education #> <chr> <dbl> <dbl+lbl> #> 1 ZA6863_1 1.49 17 #> 2 ZA6863_2 1.75 98 [Still studying] #> 3 ZA6863_3 1.39 21 #> 4 ZA6863_4 1.25 17 #> 5 ZA6863_5 0.609 19 #> 6 ZA6863_6 0.870 22 #> 7 ZA6863_7 1.40 98 [Still studying] #> 8 ZA6863_8 0.932 14 #> 9 ZA6863_9 1.42 22 #> 10 ZA6863_10 1.12 16 #> # ... with 40 more rows #> #> [[3]] #> # A tibble: 45 x 3 #> uniqid w1 age_education #> <chr> <dbl> <dbl+lbl> #> 1 ZA7576_1 0.827 26 #> 2 ZA7576_2 0.348 20 #> 3 ZA7576_3 0.385 22 #> 4 ZA7576_4 0.385 17 #> 5 ZA7576_5 0.743 31 #> 6 ZA7576_6 0.635 25 #> 7 ZA7576_7 0.883 17 #> 8 ZA7576_8 0.465 20 #> 9 ZA7576_9 1.28 17 #> 10 ZA7576_10 0.909 20 #> # ... with 35 more rows #>