sub_seq: Find sub-sequences of identical elements in a vector.

sub_seqR Documentation

Find sub-sequences of identical elements in a vector.

Description

Find sub-sequences of identical elements in a vector.

Usage

subSeq(x, item = NULL)

sub_seq(x, item = NULL)

is_grouped(x)

rle2(x)

Arguments

x

An atomic vector or a factor.

item

Optionally a specific value to look for in x.

Details

  • sub_seq is synonymous with subSeq

  • rle2 is identical to rle (from base) but rle2 works on factors as input (a factor is coerced to character).

  • is_grouped checks if the values in x are clustered into the smallest number of clusters.

Value

A dataframe.

Author(s)

Søren Højsgaard, sorenh@math.aau.dk

See Also

rle

Examples


x <- c(1, 1, 1, 0, 0, 1, 1, 1, 2, 2, 2, 1, 2, 2, 2, 3)
(ans <- subSeq(x))
ans$value

## Notice: Same results below
subSeq(x, item=1)
subSeq(x, item="1")

xc <- as.character(x)
(ans<-subSeq(xc))
ans$value

## Notice: Same results below
subSeq(xc, item="1")
subSeq(xc, item=1)

is_grouped(x)
is_grouped(sort(x))
is_grouped(xc)
is_grouped(sort(xc))

hojsgaard/doBy documentation built on May 4, 2024, 5:20 a.m.