R.utils (version 2.8.0)

seqToIntervals: Gets all contiguous intervals of a vector of indices

Description

Gets all contiguous intervals of a vector of indices.

Usage

# S3 method for default
seqToIntervals(idx, ...)

Arguments

idx

A vector of N integer indices.

...

Not used.

Value

An Nx2 integer matrix.

See Also

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

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataCamp Workspace