Learn R Programming

accelerometry (version 2.1)

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.

See Also

rle

Examples

Run this code
# Load in sample data frame
data(unidata)

# Get long vector of ID numbers
id.numbers <- unidata[,1]

# Summarize runs of ID numbers
id.summarized <- rle2(x = id.numbers)

Run the code above in your browser using DataLab