Sunday, January 21, 2018

identify longest streaks of contiguous integers in R



https://stackoverflow.com/questions/26639110/find-longest-consecutive-number-in-r


x <- c(1, 2, 10, 41, 42, 43, 50)
s <- split(x, cumsum(c(TRUE, diff(x) != 1)))
s[[which.max(sapply(s, length))]]

No comments:

Post a Comment