We can paste
the elements of the column in the 'A' dataset and use that as pattern
in grepl
to get a logical vector by checking with the strings in 'B' dataset column
i1 <- grepl(paste0("\\b(", paste(A$col, collapse="|"), ")\\b"),
B$col, ignore.case = TRUE)
i1
#[1] TRUE TRUE TRUE FALSE TRUE
B$col[i1]
data
A <- structure(list(col = c("cat", "dog", "Rat", "Parrot", "Tiger"
)), .Names = "col", class = "data.frame", row.names = c(NA, -5L
))
B <- structure(list(col = c("Give milk to cat", "dog bites",
"life span of dog is 10 years",
"Cow gives us milk", "Tiger have huge Jaws")), .Names = "col",
class = "data.frame", row.names = c(NA, -5L))