grepl("instance|percentage", labelTest$Text)
will return true if any one of instance
or percentage
is present.
How will i get true only when both the terms are present.
grepl("instance|percentage", labelTest$Text)
will return true if any one of instance
or percentage
is present.
How will i get true only when both the terms are present.
The latter one works by looking for:
Naturally if you need to find any combination of more than two words, this will get pretty complicated. Then the solution mentioned in the comments would be easier to implement and read.
Another alternative that might be relevant when matching many words is to use positive look-ahead (can be thought of as a 'non-consuming' match). For this you have to activate
perl
regex.Use intersect and feed it a grep for each word
library(data.table) #used for subsetting text vector below