I have a vector of strings, say:
vect<-c("oxidor magnesio","oxido magnesio","oxido calcio", "oxidante","oxido calcio magnesio","magnesio oxido")
I'd like to find the occurences of both words, "oxido"
and "magnesio"
.
What I'm doing 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 given order (say, for instance, "oxido" followed by "magnesio", so the correct answer would be
2
and5
). What would be the command?
Thanks,