Skip to contents

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

Usage

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

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.

Value

The modified object, invisibly.

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))

Examples

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