Learn R Programming

surveycore (version 0.8.3)

set_var_label: Set Variable Label(s)

Description

Sets variable labels using one of three conventions.

Usage

set_var_label(x, ..., variable = NULL, label = 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 the label string. Supports !!! list splicing.

variable

A character vector of variable names. Use with label.

label

A character vector of label strings, one per element of variable.

Details

Convention 1 (named ...) — recommended for interactive use:

set_var_label(x, age = "Age in years", income = "Annual income")
set_var_label(x, !!!labels_list)   # list splicing

Convention 2 (named vector in ...) — useful for programmatic use:

set_var_label(x, c(age = "Age in years", income = "Annual income"))

Convention 3 (variable + label arguments) — for vector input:

vars <- c("age", "income")
lbls <- c("Age in years", "Annual income")
set_var_label(x, variable = vars, label = lbls)

See Also

extract_var_label() to retrieve a label

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_val_labels(), 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_var_label(d, indfmpir = "Income-to-poverty ratio")

# Multiple variables
d <- set_var_label(d, bpxsy1 = "Systolic BP (1st reading)",
                      bpxdi1 = "Diastolic BP (1st reading)")

Run the code above in your browser using DataLab