rleid: Generate run-length type group id

View source: R/utils.R

rleidR Documentation

Generate run-length type group id

Description

For a vector, x, rleid creates a run-length group identifier for by grouping sequential identical elements of x.

Usage

rleid(x)

rleid2(x, na.rm = FALSE, ignore.na = FALSE)

Arguments

x

a logical, character, or numeric vector

na.rm

for rleid2, logical; if FALSE (default), NAs are kept in-place

ignore.na

for rleid2, logical; if FALSE (default), NAs are treated as a distinct group; if TRUE, NAs are ignored and will not separate runs, e.g., 1, 1, NA, 1 would be treated as a single run

Details

rleid2 identifies the nth sequence of each unique value of x.

Value

An integer vector having the same length as x.

See Also

rle; data.table::rleid

Examples

x <- LETTERS[c(1, 1, 2, 1, 1, 2, 3, NA, 3, 3, 2, 3, 1, NA)]
data.frame(
  id = x,
  rleid = rleid(x),
  rleid2 = rleid2(x, ignore.na = FALSE),
  rleid2 = rleid2(x, ignore.na = TRUE)
)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.