powered by
This function is a wrapper to base::rle() that does exactly this but is a little too picky about input values.
base::rle()
prepGroupCounts(x)
list(n = rle$lengths, names = rle$values)
The vector to process
prepGroupCounts(c(1:3, 3:1))
Run the code above in your browser using DataLab