title: Cumulative over column other than the one used for the binning
body: <p>imagine to have a 2 columns  (X,Y) file, with X  from 0 to 1 and Y from -1 to 1.</p>
  
  <p>What I want to create is a new file with 3 columns (Z,cnt, cnt_neg) such that for each value of </p>
  
  <pre><code>Z &lt;- seq(from=0,to=0.2,by=0.001)
  cnt = number of cases for  (X&gt;Z[i])
  cnt_neg = number of cases for  (X&gt;Z[i] &amp;&amp; Y&lt;0)
  </code></pre>
  
  <p>here a subsample of the data</p>
  
  <pre><code> X                          Y
  
   0.000000e+00            0.000000000
  
   6.776256e-05           -0.434395460
  
   6.345427e-03            0.006335658
  
   7.018170e-03           -0.005483665
  
   1.746639e-02            0.017460916
  
   1.424365e-01            0.138704340
  </code></pre>
  
  <p>Practically these are 2 cumulative distributions; a standard one and one done over a column other than the one used for the binning.
  I can make it working with a double loop like other languages, but I really want to work with R.</p>
  
  <p>Among the various attempts there is:</p>
  
  <pre><code>for(i in 1:length(Z)){ 
       cnt[i]&lt;-sum(rle(X&gt;Z[i])$lengths)
       cnt_neg[i]&lt;-sum(rle(X&gt;Z[i] &amp;&amp; Y&lt;0)$lengths)
       cnt[i]=cnt[i]+1
       cnt_neg[i]=cnt_neg[i]+1
  }
  </code></pre>
  
  <p>but the output is correct only for the first raw (0, 5, 2) but for the rest of the rows all remain the same except the first column.</p>