seqToIntervals {denstrip} | R Documentation |
Find contiguous sequences in a vector of integers
Description
Get all sequences of contiguous values in a vector of integers.
Usage
seqToIntervals(x)
Arguments
x |
A vector of integers, for example, representing
indices. |
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
Examples
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))
[Package denstrip version 1.5.4 Index]