You guys are working too hard. Rgames> y <- c(0,1,1,3,3,3,5,5,6) Rgames> rle(sort(y)) Run Length Encoding lengths: int [1:5] 1 2 3 2 1 values : num [1:5] 0 1 3 5 6 -- ----- Sent from my Cray XK6