Given a sequence of values of which a subset are dubbed 'hits', determine the number of runs of hits and the start and end of each run of hits.

runs_in_sequence(x, codes_for_hit = 1)

Arguments

x

A vector of values.

codes_for_run

A vector of the values in x indicating a hit.

Value

A list with a) the total number of runs, and b) a matrix with a column for the start position of each run and a column for the end position of each run.

Examples

# Generate a sequence of zeros and ones
x <- rbinom( 10, 1, .5 )
print(x)
#>  [1] 1 0 1 1 1 0 1 1 0 0
# Determine runs of ones
runs_in_sequence( x )
#> $n_runs
#> [1] 3
#> 
#> $sequences
#>      Start End
#> [1,]     1   1
#> [2,]     3   5
#> [3,]     7   8
#>