Thanks! That does exactly what I want. (Heck, maybe this should be included as a default sorted alternative to ave.) I was thinking of doing it another way using cumsums, but maybe this method is faster. Zhou