Try this also:

with(rle(v), unlist(sapply(lengths, FUN = seq)) * v)

On Mon, Sep 14, 2009 at 12:20 PM, smu <[email protected]> wrote:

> hey,
>
> I can not find a function for the following problem, hopefully you can
> help me.
>
> I have a vactor like this one
>
> v = c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE)
>
> and I would like to the TRUE values by the their "local sequence
> number".
>
> This means, the result should look thike this:
>
> c(NA,NA,1,2,NA,1,NA,1,2,3)
>
> Of course I could solve the problems using a loop, but this would be
> much to slow, because the real vector is much larger.
> Can you point me in the right direction?
>
> thank you!
>
> regards,
>  Stefan
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to