Reputation: 1471
I am looking for a partial matching between two strings, the condition would return true if all words match, but would be false otherwise. e.g.
myElem <- "a b"
would return true when matched with
nElem <- "a b c"
or
nElem<- "d g b a",
but would return false if
nElem <- "d c g a"
Can anybody suggest a way using grep or other functions? Thanks in advance.
Also any tutorial for learning the basics of the grep options?
Upvotes: 0
Views: 1776
Reputation: 99371
Have you tried agrepl
? You could adjust the max.distance
and costs
arguments if necessary.
x <- c("a b c", "d g b a", "d c g a")
agrepl("a b", x)
# [1] TRUE TRUE FALSE
Upvotes: 1