Skip to contents

Sets value labels for a single variable in a survey design object. Extra labels (for values not present in the data) are allowed — they document the full coding scheme. A warning is issued if some observed data values lack a label.

Usage

set_val_labels(x, var, labels)

Arguments

x

A survey design object.

var

<data-masked> Variable to label (bare, unquoted).

labels

A fully named vector where names are the display labels and values are the data codes (e.g., c(Male = 1L, Female = 2L)). All elements must be named.

Value

The modified survey object, invisibly.

Examples

d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
               strata = sdmvstra, nest = TRUE)
d <- set_val_labels(
  d, ridstatr, c("Interview only" = 1L, "Interview + exam" = 2L)
)