Learn R Programming

surveycore (version 0.8.3)

extract_var_label: Extract Variable Labels

Description

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

Usage

extract_var_label(x, ..., format = "named_vector", fill = NULL)

Value

  • "named_vector" (default): named character vector. Empty: character(0).

  • "list": named list of character scalars. Empty: list().

  • "data_frame": tibble with columns variable and label. Empty: zero-row tibble.

Arguments

x

A survey design object or data.frame.

...

<tidy-select> Variables to query. Supports selection helpers: tidyselect::starts_with(), tidyselect::all_of(), tidyselect::any_of(), tidyselect::matches(), etc. If empty, returns metadata for all variables. Use tidyselect::any_of() to silently skip missing variable names.

format

character(1). Output format: "named_vector" (default), "list", or "data_frame".

fill

Scalar or NULL. How to handle variables with no label: NULL (default) omits them; NA_character_ includes them with NA.

See Also

set_var_label() to set a variable label

Other metadata: classify_question_type(), extract_metadata(), extract_missing_codes(), extract_question_preface(), extract_sata(), extract_universe(), extract_val_labels(), extract_var_note(), infer_question_prefaces(), set_missing_codes(), set_question_preface(), set_sata(), set_universe(), set_val_labels(), 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)
extract_var_label(d)
extract_var_label(d, riagendr, ridageyr)
extract_var_label(d, format = "data_frame")
extract_var_label(d, fill = NA_character_)

Run the code above in your browser using DataLab