This is useful if you want to convert tagged missing values from SAS or Stata, or user-defined missings from SPSS, to regular R NA.

zap_missing(x)

Arguments

x

A vector or data frame

Examples

x1 <- labelled( c(1, 5, tagged_na("a", "b")), c(Unknown = tagged_na("a"), Refused = tagged_na("b")) ) x1
#> <Labelled double> #> [1] 1 5 NA(a) NA(b) #> #> Labels: #> value label #> NA(a) Unknown #> NA(b) Refused
zap_missing(x1)
#> <Labelled double> #> [1] 1 5 NA NA
x2 <- labelled_spss( c(1, 2, 1, 99), c(missing = 99), na_value = 99 ) x2
#> <Labelled SPSS double> #> [1] 1 2 1 99 #> Missing values: 99 #> #> Labels: #> value label #> 99 missing
zap_missing(x2)
#> <Labelled double> #> [1] 1 2 1 NA #> #> Labels: #> value label #> 99 missing
# You can also apply to data frames df <- tibble::data_frame(x1, x2, y = 4:1) df
#> # A tibble: 4 × 3 #> x1 x2 y #> <dbl+lbl> <dbl+lbl> <int> #> 1 1 1 4 #> 2 5 2 3 #> 3 NA 1 2 #> 4 NA 99 1
zap_missing(df)
#> # A tibble: 4 × 3 #> x1 x2 y #> <dbl+lbl> <dbl+lbl> <int> #> 1 1 1 4 #> 2 5 2 3 #> 3 NA 1 2 #> 4 NA NA 1