I need to find the longest consecutive subsequence of a vector, and if there are more than 1 subsequence have the same longest length, I need the last one. My code is as below:
x <- c(1, 3, 7, 11, 40:50, 90:100, 110:115)
seq_blocks <- split(x, cumsum(c(TRUE, diff(x) != 1)))
seq_longest <- seq_blocks[[which.max(lengths(seq_blocks))]]
This code seem to pick up the first longest subsequence, but I need the last one.