# Ops.rle: Unary and Binary Operations for 'rle' Objects In statnet/rle: Common Functions for Run-Length Encoded Vectors

## Description

Unary and binary Arithmetic and Logic operators (with exceptions given below) are implemented between two `rle` objects and between an `rle` object and a scalar.

## Usage

 ```1 2``` ```## S3 method for class 'rle' Ops(e1, e2) ```

## Arguments

 `e1, e2` Arguments to unary (`e1`) and binary (`e1` and `e2`) operators.

## Details

Supported operations include all elements of the `Ops` group, as well as `xor`. Within the Arithmetic and Logic operators, this includes (taken from the R help): `+`, `-`, `*`, `/`, `^`, `<` , `>`, `<=`, `>=`, `!=`, `==`, `%%`, `%/%`, `&`, `|`, `!`, and `xor`; but excludes non-vector logical functions and operators such as `isTRUE` and `&&`.

## Value

In every supported case, the operation should result in an `rle` that would have resulted had the operation been applied to the original (uncompressed) vectors, then compressed using `rle`, with the proviso that if the resulting function creates adjacent runs of the same value, they are not merged. This must be done explicitly with `compress.rle`. (At no point in the calculation are the uncompressed vectors actually constructed, of course.)

An operation between an `rle` and a zero-length object produces an empty `rle`.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28``` ```x <- rle(as.logical(rbinom(10,1,.7))) y <- rle(as.logical(rbinom(10,1,.3))) stopifnot(isTRUE(all.equal((!inverse.rle(x)),inverse.rle(!x)))) stopifnot(isTRUE(all.equal((inverse.rle(x)|inverse.rle(y)),inverse.rle(x|y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)&inverse.rle(y)),inverse.rle(x&y)))) x <- rle(sample(c(-1,+1), 10, c(.7,.3), replace=TRUE)) y <- rle(sample(c(-1,+1), 10, c(.3,.7), replace=TRUE)) stopifnot(isTRUE(all.equal((inverse.rle(x)*inverse.rle(y)),inverse.rle(x*y)))) stopifnot(isTRUE(all.equal((2*inverse.rle(y)),inverse.rle(2*y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)*2),inverse.rle(x*2)))) stopifnot(isTRUE(all.equal((inverse.rle(x)/inverse.rle(y)),inverse.rle(x/y)))) stopifnot(isTRUE(all.equal((2/inverse.rle(y)),inverse.rle(2/y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)/2),inverse.rle(x/2)))) stopifnot(isTRUE(all.equal((-inverse.rle(y)),inverse.rle(-y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)-inverse.rle(y)),inverse.rle(x-y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)%/%inverse.rle(y)),inverse.rle(x%/%y)))) stopifnot(isTRUE(all.equal(inverse.rle(x)==inverse.rle(y),inverse.rle(x==y)))) stopifnot(isTRUE(all.equal((inverse.rle(x)>inverse.rle(y)),inverse.rle(x>y)))) ```

statnet/rle documentation built on Jan. 5, 2021, 3:31 a.m.