Recode as NA based on string match
recode_as_na_str(
df,
pattern_type = "ends_with",
pattern = NULL,
case_sensitive = FALSE,
...
)
A data.frame object
One of contains', 'starts_with' or 'ends_with'.
A character pattern to match
Defaults to FALSE. Patterns are case insensitive if TRUE
Other arguments to grepl
partial_match <- data.frame(A=c("Hi","match_me","nope"), B=c(NA, "not_me","nah"))
# Replace all that end with "me" with NA
recode_as_na_str(partial_match,"ends_with","me")
#> A B
#> 1 Hi <NA>
#> 2 <NA> <NA>
#> 3 nope nah
# Do not recode, ie case-sensitive
recode_as_na_str(partial_match,"ends_with","ME", case_sensitive=TRUE)
#> A B
#> 1 Hi <NA>
#> 2 match_me not_me
#> 3 nope nah