Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

seqToIntervals

Gets all contiguous intervals of a vector of indices


Description

Gets all contiguous intervals of a vector of indices.

Usage

## 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

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

R.utils

Various Programming Utilities

v2.10.1
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.