This function replaces specific values in a variable with NA. It would most commonly be used
to remove missing values indicated with codes such as "NA", -999 or "none".
(NB: It is very similar to dplyr's na_if
but accepts more than one value.)
na_ifs(x, replace)
library(dplyr)
ess_health %>%
mutate(eisced = na_ifs(eisced, c(7, 55)))
#> # A tibble: 7,226 × 23
#> cntry gndr agea eisced pweight pspwght health height weight icbrnct etfruit
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 DE 1 52 3 2.30 0.608 1 187 78 1 1
#> 2 DE 2 52 5 2.30 0.463 2 168 110 1 4
#> 3 DE 1 62 5 2.30 0.640 1 181 84 1 5
#> 4 DE 2 62 3 2.30 1.14 3 155 63 1 5
#> 5 DE 2 20 5 2.30 0.853 1 160 70 1 2
#> 6 DE 1 49 NA 2.30 0.364 2 177 89 1 3
#> 7 DE 1 63 6 2.30 0.310 3 169 87 1 1
#> 8 DE 2 32 3 2.30 1.35 3 163 62 1 3
#> 9 DE 2 66 5 2.30 0.341 1 157 56 1 1
#> 10 DE 1 15 1 2.30 1.74 3 172 72 1 4
#> # ℹ 7,216 more rows
#> # ℹ 12 more variables: eatveg <dbl>, dosprt <dbl>, cgtsmke <dbl>,
#> # alcfreq <dbl>, fltdpr <dbl>, flteeff <dbl>, slprl <dbl>, wrhpp <dbl>,
#> # fltlnl <dbl>, enjlf <dbl>, fltsd <dbl>, cldgng <dbl>