R: How to count number of 1 and write to vector <p>I have as signal-vector that looks like this: </p> <blockquote> <p>a &lt;- c(1,1,1,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1) </p> </blockquote> <p>I will count how often a 1 occurs in one raw and write that in to a vector b e.g. for vector a it should result in: </p> <blockquote> <p>b<br> 5,2,1,1,1,1,3 </p> </blockquote> <p>The reason is that i will plot a histogram that shows me the distribution of the length of the events. Maybe there is already a function in R that does exactly that? Otherwise with if-loop? </p> <p>Cheers Greg </p>