[R] How to test if there is a subvector in a longer vector

Berend Hasselman bhh at xs4all.nl
Fri Sep 28 09:47:55 CEST 2012


On 28-09-2012, at 07:41, Atte Tenkanen <attenka at utu.fi> wrote:

> Sorry. I should have mentioned that the order of the components is important.
> 
> So c(1,4,6) is accepted as a subvector of c(2,1,1,4,6,3), but not of c(2,1,1,6,4,3).
> 
> How to test this?

See this discussion for a variety of solutions.

http://r.789695.n4.nabble.com/matching-a-sequence-in-a-vector-td4389523.html#a4393453

Berend




More information about the R-help mailing list