Skip to contents

Finds the single longest run (streak) of a specified value contained within a provided vector

Usage

find_longest_run(sample, run_value)

Arguments

sample

numeric or character vector.

run_value

number or character, the value for which to count sequential occurrences.

Value

number, the longest run (streak) of values

Examples

s <- sample(c(0, 1), size = 10, replace = TRUE)
print(s)
#>  [1] 0 1 0 1 0 1 0 1 1 0

find_longest_run(sample = s, run_value = 1)
#> [1] 2