[R] Count matches of a sequence in a vector?

Jeff Brown dopethatwantscash at yahoo.com
Wed Apr 21 20:28:54 CEST 2010


Phil's algorithm is a good one, unless you're worried about optimizing for
speed.  It makes N * M comparisons, where N is the length of the first
vector and M is the length of the second.  Explicitly iterating through the
longer vector, you could reduce the number of comparisons to M.  As is often
the case, here there's a tradeoff between human effort and computer effort.

OTOH, because explicit iteration incurs higher interpretation costs in R, it
could conceivably be that Phil's algorithm performs faster.  I don't know.
-- 
View this message in context: http://n4.nabble.com/Count-matches-of-a-sequence-in-a-vector-tp2019018p2019428.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list