Thanks guys, the "rle" function works pretty well. Thank you all for the efforts. Zheng -- View this message in context: http://r.789695.n4.nabble.com/help-program-efficiency-tp3059079p3061103.html Sent from the R help mailing list archive at Nabble.com.