Re: [R] Vectorization/Speed Problem

2007-11-20 Thread Gabor Grothendieck
Let x be the input vector and cx be the cumulative running sum of it. Then seq_along(cx) - match(cx, cx) gives increasing sequences starting at 0 and for those after the leading zeros we start them at 1 by adding cummax(x). x <- c(0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0) # input cx <- cumsum(x)

[R] Vectorization/Speed Problem

2007-11-20 Thread Tom Johnson
Hi, I cannot find a 'vectorized' solution to this 'for loop' kind of problem. Do you see a vectorized, fast-running solution? Objective: Take the value of X at each timepoint and calculate the corresponding value of Y. Leading 0's and all 1's for X are assigned to Y; otherwise Y is incremented b