longRun: Length of the longest run of a particular value in a numeric...

Description Usage Arguments Value See Also Examples

View source: R/longRun.r

Description

This function returns the lengh of the longest run of a particular numeric value in a numeric vector. A "run" is an uninterrupted sequence of the same number. Runs can be "wrapped" so that if the sequence starts and ends with the target value then it is considered as a consecutive run.

Usage

1
longRun(x, val, wrap = FALSE, na.rm = FALSE)

Arguments

x

Numeric vector.

val

Numeric. Value of the elements of x of which to calculate length of longest run.

wrap

Logical. If TRUE then runs can "wrap" from the end of x to the start of x if the first and last elements of x are equal to val.

na.rm

Logical. If TRUE then remove NAs first.

Value

Integer.

See Also

[base::rle()]

Examples

1
2
3
4
x <- c(1, 1, 1, 2, 2, 3, 4, 5, 6, 1, 1, 1, 1, 1)
longRun(x, 2)
longRun(x, 1)
longRun(x, 1, wrap=TRUE)

adamlilith/omnibus documentation built on Nov. 21, 2018, 11:01 a.m.