For instance, in this example, I would like to remove the elements in text
that contain http
and america
.
> text &l
Generally, as @akrun said:
text <- c("One word@", "112a httpSentenceamerica", "you and meamerica", "three two one")
pattern = c("http", "america")
grep(paste(pattern, collapse = "|"), text, invert = TRUE, value = TRUE)
# [1] "One word@" "three two one"
You wrote that your list of words is "long." This solution doesn't scale indefinitely, unsurprisingly:
long_pattern = paste(rep(pattern, 1300), collapse = "|")
nchar(long_pattern)
# [1] 16899
grep(long_pattern, text, invert = TRUE, value = TRUE)
# Error in grep(long_pattern, text, invert = TRUE, value = TRUE) :
But if necessary, you could MapReduce, starting with something along the lines of:
text[Reduce(`&`, Map(function(p) !grepl(p, text), long_pattern))]
# [1] "One word@" "three two one"