roll_count: Count the number of consecutive 'TRUE' elements in a Boolean...

View source: R/RcppExports.R

roll_countR Documentation

Count the number of consecutive TRUE elements in a Boolean vector, and reset the count to zero after every FALSE element.

Description

Count the number of consecutive TRUE elements in a Boolean vector, and reset the count to zero after every FALSE element.

Usage

roll_count(tseries)

Arguments

tseries

A Boolean vector of data.

Details

The function roll_count() calculates the number of consecutive TRUE elements in a Boolean vector, and it resets the count to zero after every FALSE element.

For example, the Boolean vector FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, is translated into 0, 1, 2, 0, 0, 1, 2, 3, 4, 5, 0.

Value

An integer vector of the same length as the argument tseries.

Examples

## Not run: 
# Calculate the number of consecutive TRUE elements
drop(HighFreq::roll_count(c(FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)))

## End(Not run)

algoquant/HighFreq documentation built on Feb. 9, 2024, 8:15 p.m.