powered by
The function returns where the continuous streaks start and how long they are, which can be used for efficient and flexible subsetting.
streaklog(x)whichmaxstreak(x, which = -1)
whichmaxstreak(x, which = -1)
A list (streaklog) or a numeric vector (whichmaxstreak).
(vector) A vector with missing values.
vector
(integer) In case multiple streaks of the same length are found, which of them should be returned by the vector (integer).
(integer)
The output list of streaklog contains the following elements:
streaklog
starts: the indices where the streaks start.
starts
streaks: the lengths of the individual streaks (number of values).
streaks
runs: the number of streaks.
runs
The function whichmaxstreak() will return the indices of those values that are in the longest continuous streak.
# generate a sequence of values b<-40:1 # add some gaps b[c(1:4, 15, 19, 23:27)] <- NA # the functions streaklog(b) whichmaxstreak(b)
Run the code above in your browser using DataLab