[R] sequentially summing up a elements of a vector
Martin Batholdy
batholdy at googlemail.com
Sun Jan 22 00:59:09 CET 2012
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!
More information about the R-help
mailing list