seqToIntervals: Find contiguous sequences in a vector of integers

Description Usage Arguments Value Author(s) See Also Examples

View source: R/denstrip.R

Description

Get all sequences of contiguous values in a vector of integers.

Usage

1

Arguments

x

A vector of integers, for example, representing indices. x is coerced to integer, sorted, and unique values extracted, if necessary, before finding the contiguous sequences.

Value

A matrix with one row for each sequence, and two columns containing the start and the end of the sequence, respectively.

Author(s)

Chris Jackson <chris.jackson@mrc-bsu.cam.ac.uk>. Thanks to Tobias Verbeke for the suggestion.

See Also

sectioned.density

Examples

1
2
3
4
seqToIntervals(1:10)  # [1 10]
seqToIntervals(c(1:10, 15:18, 20))  # [1 10; 15 18; 20 20]
# vectorised, so efficient for large vectors x
seqToIntervals(sample(1:1000000, size=999990)) 

Example output

  from to
1    1 10
  from to
1    1 10
2   15 18
3   20 20
     from      to
1       1  192523
2  192525  222033
3  222035  277498
4  277500  337124
5  337126  399462
6  399464  542494
7  542496  547509
8  547511  752979
9  752981  896413
10 896415  972688
11 972690 1000000

denstrip documentation built on May 2, 2019, 9:58 a.m.