How to partition a vector into groups of neighbors in R?
I have a vector, such as
c(1,3,4,5,9,10,17,29,30) and I would like to group together the elements that form a series in a ragged vector resulting in:
Naive code (of an ex-C programmer):
Now I understand that
a) R is not C (despite the curly brackets)
b) global variables are pure evil
c) that is a horribly inefficient way of achieving the result
, so any better solutions are welcome.