[R] find a sequence of characters in a vector

Ptit_Bleu ptit_bleu at yahoo.fr
Fri Jun 5 15:22:17 CEST 2009


Hello,

I'm just looking for an easy way to find the positions of a complete
sequence in a bigger vector.
For example :
c("a","z","e") in c("a","z","e","r","t","a","z","a","z","e","c")
and the result should be
1 8
that is the positions of the beginning of the complete sequence.

I tried with %in%, match, is.element but all I get is, for example
which(c("a","z","e") in c("a","z","e","r","t","a","z","a","z","e","c"))
1 2 3
meaning that each character is in the bigger vector.

It must be easy, except for me. Sorry.

If you have a solution, thanks in advance to share it.
Have a good week-end,
Ptit Bleu.

-- 
View this message in context: http://www.nabble.com/find-a-sequence-of-characters-in-a-vector-tp23888063p23888063.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list