Re: [R] find a sequence of characters in a vector

2009-06-05 Thread Gabor Grothendieck
I think I would use Sundar's solution but here are a couple more just in case: > x <- c("a", "z", "e") > y <- c("a", "z", "e", "r", "t", "a", "z", "a", "z", "e", "c") > > #1 > which(apply(embed(y, 3), 1, identical, rev(x))) [1] 1 8 > #2 > library(zoo) > which(rollapply(zoo(y), 3, identical, x, al

Re: [R] find a sequence of characters in a vector

2009-06-05 Thread Greg Snow
g 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Ptit_Bleu > Sent: Friday, June 05, 2009 7:22 AM > To: r-help@r-project.org > Subject: [R] find a sequence of characters in a vector > > &

Re: [R] find a sequence of characters in a vector

2009-06-05 Thread Sundar Dorai-Raj
use gregexpr and paste > aze <- paste(c("a", "z", "e"), collapse = "") > sequence <- paste(c("a","z","e","r","t","a","z","a","z","e","c"), collapse = > "") > gregexpr(aze, sequence, fixed = TRUE) [[1]] [1] 1 8 attr(,"match.length") [1] 3 3 HTH, --sundar On Fri, Jun 5, 2009 at 6:22 AM, Ptit_Ble

[R] find a sequence of characters in a vector

2009-06-05 Thread Ptit_Bleu
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%,