Logical-based (non-continuous) unique ID runs C++

Usage

uidvec(x, start = 0L)

Arguments

x
a vector of class "logical"

Value

a vector of "numeric"

Description

For a vector of logicals, assigns each continuous run of TRUE values a unique ID.

Examples

uidvec(c(FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,TRUE,FALSE,TRUE))
[1] 0 0 1 1 1 0 2 0 3 3 0 4