Thanks to everyone who answered, in public or in private. I successfully rewrote my function with rle.
For my sample, the total computation times (I call this function around 1000 times) are roughly the same. However, I thank you for letting me know rle, and S Poetry. Regards, Nicolas ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.