Replace values with missing values or fill missing values
Source:R/na-conversion.R
na_conversion.RdConvert between missing values and explicit replacement codes:
mvdecode()(na_if_value()): Replace specified codes withNA, like Stata'smvdecode x, mv(-98 -99).mvencode()(value_if_na()): Fill missing values with one replacement, like Stata'smvencode x, mv(0).
The aliases perform the same operations but name the replacement argument
value instead of mv.
Value
A vector with the same type and size as x, with matching values
replaced or missing values filled.
Details
Codes are matched with dplyr::na_if(); filling follows
tidyr::replace_na(). Codes and replacements are cast to the type of x, so
a lossy cast such as 1.5 for an integer vector is an error when applied.
Filling a non-SPSS vector with no missing values returns it unchanged without
casting the replacement. Both the input vector and the codes or replacement
must be supplied. For SPSS labelled
vectors (haven::labelled_spss()), user-defined missing codes and ranges
also count as missing, matching their is.na() method; labels and
missing-value metadata are retained.
See also
Other conversion functions:
type_conversion