rle2: Run length encoding (alternate implementation)
Description
Summarize vector of numeric or character values containing "runs" of repeated values. This function is very similar to the base function rle, but sometimes much faster, and different in that it returns the start/end indices for each run in addition to the run length.
Usage
rle2(x)
Arguments
x
Input vector containing either numeric or character data.
Value
The function returns a 4-column object, where each row contains information on a particular "run" of repeated values. The columns are value, start index, end index, run length.
A matrix is returned if the input vector contains numeric data, and a data frame if it contains character data.
Details
NA
References
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
# Load in sample data framedata(unidata)
# Get long vector of ID numbersid.numbers <- unidata[,1]
# Summarize runs of ID numbersid.summarized <- rle2(x = id.numbers)