Find regular sequences of integers in numeric vector v.

series(v, step = 1, minseries = 2)

Arguments

v

A numeric vector containing only whole numbers.

step

The step size and direction (distance between adjacent items) for identifying series. Note that the sign of the step matters. Use positive values for monotonically increasing series and negative values for monotonically decreasing series. Defaults to 1. Use 0 for invariant series (runs).

minseries

The minimimum series length. Defaults to 2.

Value

Numeric matrix with 1 row for each series, and three columns indicating:

  1. first: Integer at beginning of series.

  2. runstart: Index into v for start of series.

  3. runlength: Length of series.

Details

Takes a vector of whole numbers and returns a matrix with 3 columns: (1) integer at beginning of series, (2) index pointing to beginning of series, (3) length of series

Author

David Braze davebraze@gmail.com