Skip to contents

Returns value labels for one or more variables in a survey design object or data frame.

Usage

extract_val_labels(x, ..., format = "list", fill = NULL)

Arguments

x

A survey design object or data.frame.

...

<data-masked> Variable names (bare, unquoted). If empty, metadata for all variables is returned.

format

character(1). Output format: "list" (default) or "data_frame". "named_vector" is not valid for this function.

fill

Scalar or NULL. How to handle variables with no labels: NULL (default) omits them; NA_character_ includes them as NULL entries in "list" format.

Value

  • "list" (default): named list of named vectors. Empty: list().

  • "data_frame": long-format tibble with columns variable, label, value (codes coerced to character). Empty: zero-row tibble.

Examples

d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
               strata = sdmvstra, nest = TRUE)
extract_val_labels(d, riagendr)
#> named list()
extract_val_labels(d, riagendr, format = "data_frame")
#> # A tibble: 0 × 3
#> # ℹ 3 variables: variable <chr>, label <chr>, value <chr>