The out-of-bounds functions in the scales package only work with continuous ranges. This oob function works on discrete values.

censor_discrete(x, range)

Arguments

x

A vector of values.

range

A character vector of values that should be kept.

Value

x with values not in range as NA.

Examples

censor_discrete(c("a", "b", "c"), range = c("a", "b"))
#> [1] "a" "b" NA