[R] Find the first values in vector
    Dimitris Rizopoulos 
    d.rizopoulos at erasmusmc.nl
       
    Mon Nov  9 21:16:52 CET 2009
    
    
  
yet another solution is:
vec <- c(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 
FALSE)
seq_len(rle(vec)$lengths[1])
I hope it helps.
Best,
Dimitris
Grzes wrote:
> Hi !
> I have a vector:
> vec= TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE TRUE  TRUE  FALSE
> and I'm looking for a method which let me get only the first values equal
> TRUE from this vector. It means that I want to get a vector:
> vec_out =  TRUE  TRUE  TRUE  TRUE 
> 
> or posictions values = TRUE: vec_out = 1,2,3,4
-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
    
    
More information about the R-help
mailing list