I have a list of numbers that are increasing in nature (i.e. ever increasing).
alist <- c(1:20, 50:70, 210:235, 240:250)
The difference from one number to the next, is n.
I'd like to automatically split the list based on whether the difference between each item on the list is bigger than the threshold value of n.
For example, if the value of n > 20, for the particular list above it should split itself into 3 datasets.
Calling which(diff(alist) >20) tells me where I should "cut" the data up, but for the life of me I cannot figure out the next step... I might be missing something very simple here.
The result should ideally become a list of lists, or a table (I don't mind either):
[[1]]
[1] 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19 20
[[2]]
[1] 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65...
[[3]]
[1] 210 211 212 213...