Learn R Programming

cgwtools (version 3.3)

seqle: 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)

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.

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.

Author

Carl Witthoft, carl@witthoft.com

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.

See Also

rle inverse.seqle

Examples

Run this code

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)

Run the code above in your browser using DataLab