seqle: Extends 'rle' to find and encode linear sequences.

View source: R/seqle.r View source: R/seqle2.R

seqleR Documentation

Extends rle to find and encode linear sequences.

Description

The function rle, or "run-length encoder," is a simple compression scheme which identifies sequences of repeating values in a vector. seqle extends this scheme by allowing the user to specify a sequence of values with a common "slope," or delta value, between adjacent elements. seqle with an increment of zero is the same as rle.

Usage

seqle(x, incr = 1L, prec = .Machine$double.eps^0.5)

Arguments

x

The input vector of values.

incr

The desired increment between elements which specifies the sequences to search for. Note that this can be either integer or float. For floating-point sequences, see the prec argument for determining what level of precision is used to determine whether elements continue a sequence or not.

prec

Defines the required precision to which elements are compared when determining whether they are part of a sequence. Note that for integer inputs, this value is more or less meaningless.

Details

Note: the returned value is assigned the class "rle". So far as I can tell, this class has only a print method, i.e. defining what is returned to the console when the user types the name of the returned object. Since the concept of "increment" has no reliable meaning when dealing with characters or char strings, when x is non-numeric the argument incr is ignored and the function reverts to base::rle.

Value

lengths

a vector of the lengths (1 or greater) of all sequences found.

values

a vector of the initial value for each sequence. For example, if incr ==1 a values of 5 associated with a lengths of 3 represents the sequence 5,6,7.

Note

The bulk of the code is taken directly from base::rle . Thanks to "flodel" on StackOverflow for suggesting code to handle floating-point increments.

Author(s)

Carl Witthoft, carl@witthoft.com

See Also

rle inverse.seqle

Examples


x<- c(2,2,2,3:8,8,8,4,4,4,5,5.5,6)
seqle(x,incr=0)
seqle(x,incr=1)
seqle(x,incr=1.5)

cgwtools documentation built on Oct. 21, 2023, 1:06 a.m.