There should be a smarter solution to this but an approach with for loop would look like -
Seq.lengths<- c(2, 4, 2, 2, 2, 4)
increment <- 3
result <- 1:Seq.lengths[1]
for(i in Seq.lengths[-1]) {
val <- result[length(result)] + increment
result <- c(result, val:(val + i - 1))
}
result
#[1] 1 2 5 6 7 8 11 12 15 16 19 20 23 24 25 26
If you want to store the output in a list -
Seq.lengths<- c(2, 4, 2, 2, 2, 4)
increment <- 3
result <- vector('list', length(Seq.lengths))
result[[1]] <- 1:Seq.lengths[1]
for(i in 2:length(Seq.lengths)){
val <- result[[i-1]][length(result[[i-1]])] + increment
result[[i]] <- val:(val + Seq.lengths[i] - 1)
}
result
#[[1]]
#[1] 1 2
#[[2]]
#[1] 5 6 7 8
#[[3]]
#[1] 11 12
#[[4]]
#[1] 15 16
#[[5]]
#[1] 19 20
#[[6]]
#[1] 23 24 25 26