Converts select elements of a vector into NAs
This is how the end results are
NA_atandNA_ifrequire a suitable index value (x[y] <- NA)NA_atexpectsy(or the result of functiony) to beintegersNA_ifexpectsy(or the result of functiony) to belogical
NA_inandNA_outexpect some values to match onNA_inchecksx[x %in% y] <- NANA_outchecksx[x %out% y] <- NA(see fuj::match_ext)
See also
Inspired by dplyr::na_if()
Examples
let <- ordered(letters[1:5])
NA_at(let, c(1, 3, 5)) # [1] <NA> b <NA> d <NA>
#> [1] <NA> b <NA> d <NA>
#> Levels: a < b < c < d < e
NA_if(let, let <= "b") # [1] <NA> <NA> c d e
#> [1] <NA> <NA> c d e
#> Levels: a < b < c < d < e
NA_in(let, c("a", "c")) # [1] <NA> b <NA> d e
#> [1] <NA> b <NA> d e
#> Levels: a < b < c < d < e
NA_out(let, c("a", "c")) # [1] a <NA> c <NA> <NA>
#> [1] a <NA> c <NA> <NA>
#> Levels: a < b < c < d < e