Skip to content
Prev 274303 / 398506 Next

Create order of numbers based on a given vector

I think you can use the cumsum function.  If you think of your falses
to 1 and your trues to 0 then you're just sequentially adding the
numbers in the vector.

x = c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE)
y = rep(1,length(x))*(1-x)
cumsum(y)

Hope that helps,
Sam
On Thu, Oct 13, 2011 at 8:15 AM, syrvn <mentor_ at gmx.net> wrote: