Learn R Programming

surveycore (version 0.8.3)

set_val_labels: Set Value Labels

Description

Sets value labels for one or more variables using one of three conventions.

Usage

set_val_labels(x, ..., variable = NULL, labels = NULL)

Value

The modified object, invisibly.

Arguments

x

A survey design object or a data frame.

...

Named arguments where the name is the variable and the value is a fully named vector of value labels. Supports !!! list splicing.

variable

A character vector of variable names.

labels

A list of named vectors, one per element of variable. When variable has length 1, a bare named vector is also accepted.

Details

Convention 1 (named ...) — recommended:

set_val_labels(x, sex = c(Male = 1L, Female = 2L))

Convention 2 (single named list in ...):

set_val_labels(x, list(sex = c(Male = 1L, Female = 2L)))

Convention 3 (variable + labels):

set_val_labels(x, variable = "sex", labels = c(Male = 1L, Female = 2L))

See Also

extract_val_labels() to retrieve value labels

Other metadata: classify_question_type(), extract_metadata(), extract_missing_codes(), extract_question_preface(), extract_sata(), extract_universe(), extract_val_labels(), extract_var_label(), extract_var_note(), infer_question_prefaces(), set_missing_codes(), set_question_preface(), set_sata(), set_universe(), set_var_label(), set_var_note(), survey_metadata(), survey_weighting_history()

Examples

Run this code
d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
               strata = sdmvstra, nest = TRUE)
d <- set_val_labels(d, riagendr = c(Male = 1L, Female = 2L))

Run the code above in your browser using DataLab