title: serially subtract from vector elements
body: <p>I need to subtract a number from a vector in such a way that it is subtracted serially from the elements.  As an example, consider the vector <code>a = c(8, 4)</code>. If I want to serially subtract 9 from this vector, I first subtract 9 from the first vector element, 8. That leaves 0 for the first element with a reminder of 1, that then gets subtracted from the second element. That leaves 4-1=3 for the second vector element.</p>
  
  <p>I can do this with a bunch of inelegant if-else statement.  There must be a better way.  It would be easier to show examples:</p>
  
  <p>I assume that the serial subtraction function is called serialSub.</p>
  
  <pre><code>a = c(8,4)
  serialSub(a,4)
  &gt; [1] 4 4
  
  serialSub(a,8)
  &gt; [1] 0 4
  
  serialSub(a,9)
  &gt; [1] 0 3
  
  serialSub(a,13)
  &gt; [1] 0 0
  
  serialSub(a,0)
  &gt; [1] 8 4
  </code></pre>