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
I have a fairly similar solution to Marius, his works as well as mine but the mechanisms are slightly different so I thought I may as well post it:
findIntRuns <- function(run){
rundiff <- c(1, diff(run))
difflist <- split(run, cumsum(rundiff!=1))
unname(sapply(difflist, function(x){
if(length(x) == 1) as.character(x) else paste0(x[1], ":", x[length(x)])
}))
}
lapply(z, findIntRuns)
Which produces:
$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"