Learn R Programming

surveycore (version 0.8.3)

set_missing_codes: Set Missing Code(s)

Description

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)

Value

The modified object, invisibly.

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.

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.

See Also

Other metadata: classify_question_type(), extract_metadata(), extract_missing_codes(), extract_question_preface(), extract_sata(), extract_universe(), extract_val_labels(), extract_var_label(), extract_var_note(), infer_question_prefaces(), 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(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)

Run the code above in your browser using DataLab