[R] remove loop which compares row i to row i-1

jcrosbie james at crosb.ie
Mon Jul 16 18:27:55 CEST 2012


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.



More information about the R-help mailing list