statistics - How to find if the numbers are continuous in R? -
i have range of values
c(1,2,3,4,5,8,9,10,13,14,15) and want find ranges numbers become discontinuous. want output:
(1,5) (8,10) (13,15) i need find break points.
i need in r.
x <- c(1:5, 8:10, 13:15) rr <- rle(x - seq_along(x)) rr$values <- seq_along(rr$values) s <- split(x, inverse.rle(rr)) s # $`1` # [1] 1 2 3 4 5 # # $`2` # [1] 8 9 10 # # $`3` # [1] 13 14 15 ## , *literally* asked for: cat(paste0("(", gsub(":", ",", sapply(s, deparse)), ")"), sep="\n") # (1,5) # (8,10) # (13,15)
Comments
Post a Comment