I have some data in a list that I need to look for continuous runs of integers (My brain thinkrle
but don\'t know how to use it here).
It\'s easier to l
Here is an attempt using diff
and tapply
returning a character vector
runs <- lapply(z, function(x) {
z <- which(diff(x)!=1);
results <- x[sort(unique(c(1,length(x), z,z+1)))]
lr <- length(results)
collapse <- rep(seq_len(ceiling(lr/2)),each = 2, length.out = lr)
as.vector(tapply(results, collapse, paste, collapse = ':'))
})
runs
$greg
[1] "7:11" "20:24" "30:33" "49"
$researcher
[1] "42:48"
$sally
[1] "25:29" "37:41"
$sam
[1] "1:6" "16:19" "34:36"
$teacher
[1] "12:15"