View source: R/harmonize_values.R
| harmonize_values | R Documentation |
Convert heterogeneous labelled survey vectors into a harmonized representation with standardized value labels, numeric codes, and missing value definitions.
harmonize_values(
x,
harmonize_label = NULL,
harmonize_labels = NULL,
na_values = c(do_not_know = 99997, declined = 99998, inap = 99999),
na_range = NULL,
id = "survey_id",
name_orig = NULL,
remove = NULL,
perl = FALSE
)
x |
A labelled survey vector. |
harmonize_label |
Optional harmonized variable label. Defaults to the original variable label. |
harmonize_labels |
A list or data frame containing
|
na_values |
Named numeric vector defining harmonized user-defined missing values. |
na_range |
Reserved for compatibility with the original interface. The source vector's missing-value range is retained. |
id |
Survey identifier. If |
name_orig |
Reserved for compatibility with the original
interface. The original object name is derived from |
remove |
Optional regular expression identifying characters to remove before matching. |
perl |
Logical. Use Perl-compatible regular expressions during preliminary label matching. |
The harmonization rules supplied through harmonize_labels
must contain three elements:
from: regular expressions matching original value labels.
to: harmonized value labels.
numeric_values: harmonized numeric codes.
Matching is case-insensitive. Periods and parentheses are removed before matching.
For exact value-label mappings defined in a crosswalk table,
use crosswalk_surveys().
A retroharmonize_labelled_spss_survey vector containing
harmonized values, labels, missing value definitions, and
source-specific coding metadata.
crosswalk_surveys(), harmonize_var_names()
Other harmonization functions:
collect_val_labels(),
create_codebook(),
crosswalk_surveys(),
harmonize_na_values(),
harmonize_survey_values(),
harmonize_var_names(),
is.crosswalk_table(),
label_normalize()
var1 <- labelled::labelled_spss(
x = c(1, 0, 1, 8, 9),
labels = c(
"TRUST" = 1,
"NOT TRUST" = 0,
"DON'T KNOW" = 8,
"INAP. HERE" = 9
),
na_values = c(8, 9)
)
harmonize_values(
var1,
harmonize_labels = list(
from = c("^trust", "^not", "^don", "^inap"),
to = c("trust", "not_trust", "do_not_know", "inap"),
numeric_values = c(1, 0, 99997, 99999)
),
na_values = c("do_not_know" = 99997, "inap" = 99999)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.