I have a set of strings I need to manipulate. Of each, in case they include a set of substrings, I want to keep the substring, otherwise leave it untouched.
Here follows an example:
keep <- c("USA","UNITED STATES")
keep <- paste0(paste0(" ",keep,"$"),collapse="|")
data <- c("DETROIT","DETROIT USA","DETROIT UNITED STATES")
expected_result <- c("DETROIT","USA","UNITED STATES")