Learn R Programming

accelerometry (version 3.1.2)

rle2: Run Length Encoding (Alternate Implementation)

Description

Summarizes vector containing runs of repeated values. Very similar to rle, but sometimes much faster, and with an option to return the start/end indices for each run.

Usage

rle2(x, class = NULL, indices = FALSE)

Arguments

x

Vector (see class).

class

Character string specifying class of x. If unspecified, function figures it out (at cost of slightly slower run time).

indices

Logical value for whether to record start/stop positions in addition to values and lengths for each run.

Value

Integer or numeric matrix.

Examples

Run this code
# NOT RUN {
# Create dummie vector x
x <- c(0, 0, 0, -1, -1, 10, 10, 4, 6, 6)

# Summarize x using rle2
x.summarized <- rle2(x)

# Repeat, but also record start/stop indices for each run
x.summarized <- rle2(x = x, indices = TRUE)


# }

Run the code above in your browser using DataLab