Gets all contiguous intervals of a vector of indices.

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

Arguments

idx

A vector of N integer indices.

...

Not used.

Value

An Nx2 integer

matrix.

Author

Henrik Bengtsson

See also

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

Examples

x <- 1:10
y <- seqToIntervals(x)
print(y)  # [1 10]
#>      from to
#> [1,]    1 10

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

z <- intervalsToSeq(y)
print(z)
#>  [1]  1  2  3  4  5  6  7  8  9 10 15 16 17 18 20
stopifnot(all.equal(x,z))