title: Split the vector into equal height parts
body: <p>I have a logical vector <code>y</code> and I want to split it into <code>N</code> parts such that each part has the same number of <code>TRUE</code> values (I do <em>not</em> care how many <code>FALSE</code> values are in each part). Specifically, I want an integer vector <code>b</code> of length <code>N+1</code> such that <code>b[1]=1</code>, <code>b[N+1]=length(y)+1</code> and <code>abs(sum(y[b[i]:b[i+1])-sum(y)/N)&lt;1</code>. </p>
  
  <p>The algorithm is trivial (use <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/cumsum.html" rel="nofollow"><code>cumsum</code></a> and <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/which.html" rel="nofollow"><code>which</code></a> in a loop) but I want to avoid the loop.</p>