Convert the TRUE values in a vector into a sequence by groups of values.

TrueSeq(inLogi, zero2NA = FALSE)

Arguments

inLogi

The input logical vector.

zero2NA

Logical. Should the zeroes in the result be converted to NA. Defaults to FALSE.

Value

A numeric vector

References

http://stackoverflow.com/a/21328046/1270695

Author

Ananda Mahto

Examples

set.seed(1) x <- sample(c(TRUE, FALSE), 100, TRUE) TrueSeq(x)
#> [1] 1 0 2 2 0 3 3 3 0 0 4 4 4 4 4 0 0 0 0 5 5 5 5 5 5 #> [26] 5 0 6 6 0 0 0 7 0 8 8 0 9 0 0 0 0 10 0 0 0 0 0 11 11 #> [51] 0 12 0 0 13 13 0 0 0 14 14 0 0 0 0 0 0 15 0 0 0 0 16 16 16 #> [76] 0 0 17 17 0 0 0 18 18 18 0 19 0 20 0 21 21 0 0 22 22 22 0 0 23