This question already has an answer here:
- Sequence length encoding using R 6 answers
This is a duplicate question to this, except for R rather than Python.
I'd like to identify groups of contiguous (some people call them continuous) integers in a list, where duplicate entries are treated as existing within the same range. Therefore:
myfunc(c(2, 3, 4, 4, 5, 12, 13, 14, 15, 16, 17, 17, 20))
returns:
min max
2 5
12 17
20 20
Although any output format would be fine. My current brute-force, for-loop method is pretty slow.
(Apologies if I could have easily re-interpreted the Python answer and I'm being stupid!)
Just use
diff
: