Perhaps I misunderstand you, but ?cumsum.

x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0)
y <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4)
identical(cumsum(x), y)

Michael

On Sat, Jan 21, 2012 at 6:59 PM, Martin Batholdy
<batho...@googlemail.com> wrote:
> Hi,
>
>
> I have a somewhat abstract and tricky problem (at least for me).
>
>
> Perhaps someone here can help me:
>
>
> I would like to convert:
>
> x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0)
>
> into
>
> x <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4)
>
>
> every 1 in x marks kind of a 'border' which is separated in different 
> 'regions' in the new x.
>
>
>
> thanks for any suggestions!
>
> ______________________________________________
> R-help@r-project.org 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.

______________________________________________
R-help@r-project.org 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