R grep finds multiple complete words in a vector
I have a vector of strings, say:
vect<-c("oxidor magnesio","oxido magnesio","oxido calcio", "oxidante","oxido calcio magnesio","magnesio oxido")
I would like to find occurrences of both words, "oxido"
and "magnesio"
. What i do is
intersect(grep("\\boxido\\b",vect),grep("\\bmagnesio\\b",vect))
But,
- Question 1 : is there any direct grep command to achieve it?
- Question 2 : Suppose I want to find occurrences of both words, but in a specific order (say, for example, "oxide" followed by "magnesio", so the correct answer is
2
and5
). Which team?
Thank,
+3
source to share