seqToIntervals: Gets all contiguous intervals of a vector of indices

Description Usage Arguments Value Author(s) See Also Examples

Description

Gets all contiguous intervals of a vector of indices.

Usage

1
2
## Default S3 method:
seqToIntervals(idx, ...)

Arguments

idx

A vector of N integer indices.

...

Not used.

Value

An Nx2 integer matrix.

Author(s)

Henrik Bengtsson

See Also

*intervalsToSeq(). To identify sequences of equal values, see rle().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x <- 1:10
y <- seqToIntervals(x)
print(y)  # [1 10]

x <- c(1:10, 15:18, 20)
y <- seqToIntervals(x)
print(y)  # [1 10; 15 18; 20 20]

z <- intervalsToSeq(y)
print(z)
stopifnot(all.equal(x,z))

Example output

Loading required package: R.oo
Loading required package: R.methodsS3
R.methodsS3 v1.7.1 (2016-02-15) successfully loaded. See ?R.methodsS3 for help.
R.oo v1.22.0 (2018-04-21) successfully loaded. See ?R.oo for help.

Attaching package: 'R.oo'

The following objects are masked from 'package:methods':

    getClasses, getMethods

The following objects are masked from 'package:base':

    attach, detach, gc, load, save

R.utils v2.8.0 successfully loaded. See ?R.utils for help.

Attaching package: 'R.utils'

The following object is masked from 'package:utils':

    timestamp

The following objects are masked from 'package:base':

    cat, commandArgs, getOption, inherits, isOpen, parse, warnings

     from to
[1,]    1 10
     from to
[1,]    1 10
[2,]   15 18
[3,]   20 20
 [1]  1  2  3  4  5  6  7  8  9 10 15 16 17 18 20

R.utils documentation built on Sept. 26, 2021, 9:07 a.m.