[R] Faster way to implement this search?

Sarah Goslee sarah.goslee at gmail.com
Fri Mar 16 18:23:42 CET 2012

There's almost certainly a better way, but I'd be more inclined to look for
it if you'd provide a small reproducible example so I could actually try it.
Without knowing the structure of your data, it's very hard to offer


On Fri, Mar 16, 2012 at 12:59 PM, Walter Anderson <wandrson01 at gmail.com> wrote:
> I am working on a simulation where I need to count the number of matches for
> an arbitrary pattern in a large sequence of binomial factors.  My current
> code is
>    for(indx in 1:(length(bin.05)-3))
>      if ((bin.05[indx] == test.pattern[1]) && (bin.05[indx+1] ==
> test.pattern[2]) && (bin.05[indx+2] == test.pattern[3]))
>        return.values$count.match.pattern[1] =
> return.values$count.match.pattern[1] + 1
> Since I am running the above code for each simulation multiple times on
> sequences of 10,000,000 factors the code is taking longer than I would like.
>   Is there a better (more "R" way of achieving the same answer?
> Walter Anderson
Sarah Goslee

More information about the R-help mailing list