You want to use cumsum
here, for the cumulative sum(s) of a given condition.
> v1 <- c(0, 0, 1, 0, 0, 0, 1, 1, 1, 10, 2, 0)
> v2 <- cumsum(v1 == 0)
> v3 <- cumsum(v1 > 0)
> data.frame(v1, v2, v3)
## v1 v2 v3
## 1 0 1 0
## 2 0 2 0
## 3 1 2 1
## 4 0 3 1
## 5 0 4 1
## 6 0 5 1
## 7 1 5 2
## 8 1 5 3
## 9 1 5 4
## 10 10 5 5
## 11 2 5 6
## 12 0 6 6