[R] Searching for a pattern within a vector

Berend Hasselman bhh at xs4all.nl
Fri Feb 24 09:24:41 CET 2012


On 24-02-2012, at 08:30, Apoorva Gupta wrote:

> Dear R users,
> 
> I have a data.frame as follows
> 
>     a b c d e
> [1,] 1 1 1 0 0
> [2,] 1 1 0 0 0
> [3,] 1 1 0 0 0
> [4,] 0 1 1 1 1
> [5,] 0 1 1 1 1
> [6,] 1 1 1 1 1
> [7,] 1 1 1 0 1
> [8,] 1 1 1 0 1
> [9,] 1 1 1 0 0
> [10,] 1 1 1 0 0
> 
> Within these 4 vectors, I want to choose those vectors for which I
> have the pattern (0,0,1,1,1,1) occuring anywhere in the vector.
> This means I want vectors a,c,e and not b and d.
> 

See this thread "[R] matching a sequence in a vector?" :

http://tolstoy.newcastle.edu.au/R/e17/help/12/02/4201.html

Berend



More information about the R-help mailing list