title: R: removing repetitions from one column and sum another
body: <p>Say I have a data matrix that looks like this:</p>
  
  <pre><code>   X1  X2      X3
  1   1 869 1956.78
  2   1 869 2006.52
  3   1 869 1592.80
  4   1 869 6620.00
  5   1 869  228.22
  6   1 869  110.15
  7   1 869 1350.79
  8   1 869   78.36
  9   1 869  118.61
  10  1 869  453.99
  11  1 869 5393.16
  12  1 869 1641.34
  13  1 869  885.80
  14  1 869  352.80
  15  1 869  105.64
  16  2   1    0.00
  17  2 313    0.00
  18  2 467    0.00
  19  2 495    0.00
  20  2 135    0.00
  21  2 769    0.00
  22  2 770    0.00
  23  2 771    0.00
  24  1 869  375.60
  25  2 869    0.00
  26  2 869    0.00
  27  2 869    0.00
  28  2   1    0.00
  29  2   1    0.00
  30  2 467    0.00
  </code></pre>
  
  <p>I want to format it as so:</p>
  
  <pre><code>   X1  X2       X3
  1   1 869 22894.96
  2   2   1    0.00
  3   2 313    0.00
  4   2 467    0.00
  5   2 495    0.00
  6   2 135    0.00
  7   2 769    0.00
  8   2 770    0.00
  9   2 771    0.00
  10  1 869  375.60
  11  2 869    0.00
  12  2   1    0.00
  13  2 467    0.00
  </code></pre>
  
  <p>So basically, I want to remove <strong>consecutive</strong> repetitions in <code>X2</code> and <code>X1</code> and then sum the associated values in <code>X3</code>.  </p>
  
  <p>The seems like a very complex idea to me, perhaps there is an elegant solution.  I know that if X3 is not zero, then the corresponding value in X1 is "1".  So I can determine where this happens by using placement:</p>
  
  <pre><code>placement &lt;- grep(1, df$X1)
  </code></pre>
  
  <p>I'm not sure how to continue from here.  </p>