Skip to contents

Converts all tagged NAs to regular (untagged) NA values, effectively removing the missing value type information. Works with data from any format: read_spss(), read_por(), read_stata(), read_sas(), or read_xpt().

Usage

strip_tags(x, ...)

Arguments

x

A numeric vector with tagged NAs, or a data frame.

...

For a data frame: the columns to convert (tidyselect). If empty, every numeric column is converted. Ignored for vectors.

Value

The input with all tagged NAs replaced by regular NA. Value labels for missing types are removed; labels for valid values and the variable label are preserved. A haven_labelled input stays haven_labelled, so the labels survive write_spss() and write_stata(). A data frame is returned with the selected columns converted.

Examples

# \donttest{
if (requireNamespace("haven", quietly = TRUE)) {
  x <- set_na(c(1, 2, -9, 3, -8), -9, -8)
  # Remove tag information: all missings become plain NA
  strip_tags(x)
}
#> <labelled<double>[5]>
#> [1]  1  2 NA  3 NA
# }