Thank you, That was very helpful. I do have another problem along the same lines. But I can not think of a way to do this with a function like ddply or aggregate. Example: x = sample(0:1,42,TRUE) [1] 1 1 1 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 I want to find create a new vector such that the sums of the 1's stops each time there is a 0 and starts again next time there is a one. Output would be: 4,1, 5, 1,2,2,1,2,3
-- View this message in context: http://r.789695.n4.nabble.com/remove-loop-which-compares-row-i-to-row-i-1-tp4635327p4636662.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org 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.