Learn R Programming

sjmisc (version 1.2)

get_na: Retrieve missing values of labelled variables

Description

This function retrieves the value codes associated with missing values of variables of an imported SPSS, SAS or STATA data set (via read_spss, read_sas or read_stata), where missing values have not been replaced with NAs after import, or of labelled vectors.

Usage

get_na(x)

Arguments

x
Variable (vector) with value label attributes, including missing value codes (see labelled).

Value

  • The missing values associated with value labels from x, or NULL if x has no missing value attribute.

Details

Other statistical software packages (like 'SPSS') allow to define multiple missing values, e.g. not applicable, refused answer or "real" missing. These missing types may be assigned with different values, so it is possible to distinguish between these missing types. In R, multiple declared missings cannot be represented in a similar way. However, labelled vectors allow to indicate different missings through the is_na-attr. Technically, these "missings" are stored as normal values. Thus, the table command, for instance, would include these values by default. The sjmisc package offers capabilities to deal with multiple declared missings and enhances the possibilities to work with labelled data, allowing for easy access of multiple declared missings or conversion into NA etc. Furthermore, see 'Details' in get_values.

See Also

get_labels to get value labels, or get_values to get values associated with labels; see set_na to replace specific values with NA and to_na to convert missing value codes into NA; see get_na_flags to get a logical vector of missing flags.

Examples

Run this code
# create labelled factor, with missing flag
x <- labelled(c("M", "M", "F", "X", "N/A"),
              c(Male = "M", Female = "F",
                Refused = "X", "Not applicable" = "N/A"),
              c(FALSE, FALSE, TRUE, TRUE))
get_na(x)

# create labelled integer, with missing flag
x <- labelled(c(1, 2, 1, 3, 4, 1),
              c(Male = 1, Female = 2, Refused = 3, "N/A" = 4),
              c(FALSE, FALSE, TRUE, TRUE))
get_na(x)

Run the code above in your browser using DataLab