title: Cumulative sum in a matrix
body: <p>I have a matrix like</p>
  
  <pre><code>A= [ 1 2 4
       2 3 1
       3 1 2 ]
  </code></pre>
  
  <p>and I would like to calculate its cumulative sum by row and by column, that is, I want the result to be</p>
  
  <pre><code>B = [ 1  3  7 
        3  8  13 
        6  12 19 ]
  </code></pre>
  
  <p>Any ideas of how to make this in R in a fast way? (Possibly using the function cumsum)
  (I have huge matrices)</p>
  
  <p>Thanks!</p>