Suppose I have a vector of dimension n and it is composed of 0 and 1. Then I divide this vector into m equal bins. A bin is called active if it contains at least one "1". I want to write a command that returns the place of active bins and how many "1" they contain.
For example, I have this vector: n=15, m=5
[1 0 0 | 0 1 1 | 0 0 0 | 0 1 0| 1 1 1] I want to have matrix [1 2 4 5] (the active bins) and [1 2 1 3] (how many 1 they contain).
Can I write this in R without using for loops?