Skip to contents

Returns missing value sentinel codes for one or more variables in a survey design object or data frame.

Usage

extract_missing_codes(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 codes: NULL (default) omits them; NA_character_ includes them as NULL entries in "list" format.

Value

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

  • "data_frame": long-format tibble with columns variable, description (NA if codes vector is unnamed), code (coerced to character). Empty: zero-row tibble.

Examples

d <- as_survey(nhanes_2017, ids = sdmvpsu, weights = wtint2yr,
               strata = sdmvstra, nest = TRUE)
d <- set_missing_codes(d, ridageyr = c("Not applicable" = 999L))
extract_missing_codes(d, ridageyr)
#> $ridageyr
#> Not applicable 
#>            999 
#> 
extract_missing_codes(d, ridageyr, format = "data_frame")
#> # A tibble: 1 × 3
#>   variable description    code 
#>   <chr>    <chr>          <chr>
#> 1 ridageyr Not applicable 999