Skip to contents

The function returns where the continuous streaks start and how long they are, which can be used for efficient and flexible subsetting.

Usage

streaklog(x)

whichmaxstreak(x, which = -1)

Arguments

x

(vector) A vector with missing values.

which

(integer) In case multiple streaks of the same length are found, which of them should be returned by the vector (integer).

Value

A list (streaklog) or a numeric vector (whichmaxstreak).

Details

The output list of streaklog contains the following elements:

starts: the indices where the streaks start.

streaks: the lengths of the individual streaks (number of values).

runs: the number of streaks.

The function whichmaxstreak() will return the indices of those values that are in the longest continuous streak.

Examples

# generate a sequence of values
  b<-40:1
# add some gaps
  b[c(1:4, 15, 19, 23:27)]  <- NA
# the functions
  streaklog(b)
#> $starts
#> [1]  5 16 20 28
#> 
#> $streaks
#> [1] 10  3  3 13
#> 
#> $runs
#> [1] 4
#> 
  whichmaxstreak(b)
#>  [1] 28 29 30 31 32 33 34 35 36 37 38 39 40