rle
to find and encode linear sequences.
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
.
seqle(x, incr = 1L, prec = .Machine$double.eps^0.5)
a vector of the lengths (1 or greater) of all sequences found.
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
.
The input vector of values.
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.
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.
Carl Witthoft, carl@witthoft.com
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
.
rle
inverse.seqle
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