I have the following vector
x <- c(1,3,4,5,8,9,10,13)
I wish to transform it into a set of intervals:
iwant <- list(1, c(3,5), c(8,10), 13)
iwant
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 3 5
#>
#> [[3]]
#> [1] 8 10
#>
#> [[4]]
#> [1] 13
is there an easy way to tranform x
such into groups of interval
ranges in R or with Rcpp (real x
vector may be have up to ~ 80M values) that I've completely missed? If not can someone point me to an algorithm I can't seem to figure it out.