Maximum number of consecutive values in a vector

maxConsecutive(vec, val = TRUE, gte = NA)

Arguments

vec

a vector

val

the value to search for consecutive values

gte

return indices for values greater than or equal to this number of consecutive values (default= NA, which is only the max). Note that if gte > the max, the index returned will be NA

Value

the number of consecutive values. 0 means that value is not present in the vector

Examples

maxConsecutive(c(1,2,7,5,7,7,7,3,4),val = 7)
#> $max
#> [1] 3
#> 
#> $index
#> [1] 5 6 7
#>