View source: R/harmonize_survey_values.R
| harmonize_survey_values | R Documentation |
Harmonize value codes and value labels across multiple surveys and combine them into a single data frame.
harmonize_survey_values(survey_list, .f, status_message = FALSE)
harmonize_waves(waves, .f, status_message = FALSE)
survey_list |
A list of surveys (data frames). In earlier versions this argument was called
|
.f |
A function applied to each labelled variable
(class |
status_message |
Logical. If |
waves |
A list of surveys. Deprecated. |
The function first aligns the structure of all surveys by ensuring that they contain the same set of variables. Missing variables are added and filled with appropriate missing values depending on their type.
Variables of class "retroharmonize_labelled_spss_survey" are then
harmonized by applying a user-supplied function .f to each variable
separately within each survey.
The harmonization function .f must return a vector of the same length
as its input. If .f returns NULL, the original variable is kept
unchanged.
Prior to version 0.2.0 this function was called harmonize_waves.
The earlier form harmonize_waves is deprecated.
The function is currently called harmonize_waves.
A data frame containing the row-wise combination of all surveys, with harmonized labelled variables and preserved attributes describing the original surveys.
Other harmonization functions:
collect_val_labels(),
crosswalk_surveys(),
harmonize_na_values(),
harmonize_values(),
harmonize_var_names(),
is.crosswalk_table(),
label_normalize()
examples_dir <- system.file("examples", package = "retroharmonize")
survey_files <- dir(examples_dir, pattern = "\\.rds$", full.names = TRUE)
surveys <- read_surveys(
survey_files,
export_path = NULL
)
# Keep only supported variable types
surveys <- lapply(
surveys,
function(s) {
s[, vapply(
s,
function(x) inherits(x, c(
"retroharmonize_labelled_spss_survey",
"numeric",
"character",
"Date"
)),
logical(1)
)]
}
)
# Identity harmonization (no-op)
harmonized <- harmonize_survey_values(
survey_list = surveys,
.f = function(x) x,
status_message = FALSE
)
head(harmonized)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.