Skip to content
Prev 285470 / 398502 Next

matching a sequence in a vector?

Thankyou all for your great, and creative solutions.

There is definately more than one way to skin a cat.

A colleague alerted me to another solution:

seq.strt <- which( sapply( 1:(length(exmpl)-length(patrn)+1), function(i) isTRUE( all.equal( patrn, exmpl[ i + 0:(length(patrn)-1) ] ) ) ) ) 

Apparently this came from a post in the help archive that my searches missed.

I think the solutions you have put up are more readable.

Kind regards

Matt
********************************DISCLAIMER****************************
The information contained in the above e-mail message or messages 
(which includes any attachments) is confidential and may be legally 
privileged.  It is intended only for the use of the person or entity 
to which it is addressed.  If you are not the addressee any form of 
disclosure, copying, modification, distribution or any action taken 
or omitted in reliance on the information is unauthorised.  Opinions 
contained in the message(s) do not necessarily reflect the opinions 
of the Queensland Government and its authorities.  If you received 
this communication in error, please notify the sender immediately 
and delete it from your computer system network.