Change specified values to NA

specify_missing(x, ..., default_missing = c("", NA, "blanks"))

Arguments

x

vector

...

values that should be changed to NA if found in x

default_missing

a vector with additional default values to change to NA. These are treated the same as ... but are added by default if not removed. A special value "blank" can be used to indicate all empty strings (all characters matching [:blank:], see regex).

Value

x itself but with specified values set to NA.

Examples

x <- sample(100) x[sample(100, 10)] <- 999 specify_missing(x, 999)
#> [1] 45 23 76 63 47 31 NA 73 69 5 NA 79 77 2 62 55 43 86 #> [19] 84 91 44 61 NA 70 97 4 78 35 82 7 32 53 NA NA 10 NA #> [37] 92 74 17 52 56 67 95 1 6 98 51 46 57 25 96 37 8 33 #> [55] NA 80 19 28 72 11 26 93 87 99 3 75 89 60 NA 100 54 NA #> [73] 48 85 27 71 12 64 94 66 29 50 30 90 21 83 58 NA 18 36 #> [91] 40 13 16 49 14 42 15 39 20 41