Learn R Programming

sjmisc (version 2.3.0)

zap_na_tags: Convert tagged NA values into regular NA

Description

Replaces all tagged_na values with regular NA.

Usage

zap_na_tags(x, ...)

Arguments

x
A labelled vector with tagged_na values, or a data frame with such vectors.
...
Optional, unquoted names of variables. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or dplyr's select_helpers. The latter must be stated as formula (i.e. beginning with ~). See 'Examples' or package-vignette.

Value

x, where all tagged_na values are converted to NA.

See Also

set_na and get_na; drop_labels to drop labels from zero-count values.

Examples

Run this code
library(haven)
x <- labelled(c(1:3, tagged_na("a", "c", "z"), 4:1),
              c("Agreement" = 1, "Disagreement" = 4, "First" = tagged_na("c"),
                "Refused" = tagged_na("a"), "Not home" = tagged_na("z")))
# get current NA values
x
get_na(x)
zap_na_tags(x)
get_na(zap_na_tags(x))

# also works with non-labelled vector that have tagged NA values
x <- c(1:5, tagged_na("a"), tagged_na("z"), NA)
haven::print_tagged_na(x)
haven::print_tagged_na(zap_na_tags(x))

Run the code above in your browser using DataLab