[R] Searching for a pattern within a vector

Apoorva Gupta apoorva.nipfp at gmail.com
Fri Feb 24 08:30:00 CET 2012


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.

Is there any grep feature which can help me do this?
Thank you
Apoorva



-- 
Apoorva Gupta
Consultant
National Institute of Public Finance and Policy



More information about the R-help mailing list