I am currently working on optimization of a R code. So, I try to avoid dynamic memory allocation, FOR loop, ... But, I have some difficulties with some FOR loop, I need to create a behaviour like this :
INPUT :
v <- c(TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,FALSE)
OUTPUT :
[1] 0 0 0 1 1 2 3 3 3 3
I think, the easiest way will be to be able to count the number of occurence of "TRUE" to the current index of the vector. If you have any idea ... Remember to avoid FOR loop and non-optimize code.
Thanks