Skip to contents

Sets missing-value codes for one or more variables. Missing codes are atomic vectors documenting which data values represent missing data (e.g., c(Refused = -2L, DontKnow = -1L)).

Usage

set_missing_codes(x, ..., variable = NULL, codes = NULL)

Arguments

x

A survey design object or a data frame.

...

Named arguments where the name is the variable and the value is a named atomic vector of missing codes. Supports !!! list splicing.

variable

A character vector of variable names. Use with codes.

codes

A list of named atomic vectors, one per element of variable. When variable has length 1, a bare named atomic vector is also accepted.

Value

The modified object, invisibly.

Details

Supports Conventions 1, 2, and 3 — see set_var_label() for details on the calling conventions. For Convention 3 with a single variable, a bare named atomic vector is accepted in addition to a list.

Examples

d <- as_survey(gss_2024, ids = vpsu, weights = wtssps,
               strata = vstrat, nest = TRUE)
d <- set_missing_codes(d, happy = c(Refused = -1L, DK = -2L))
extract_missing_codes(d, happy)
#> $happy
#> Refused      DK 
#>      -1      -2 
#>