title: I want to find the depreciation using colSums
body: <p>I have a table (let's name it development.costs), as below:</p>
  
  <p>1 2 3 4<br>
  4 5 6 7<br>
  8 9 1 2         </p>
  
  <p>Each column represents a year.</p>
  
  <p>I want to create another table (let's name it depreciation.costs) with the same dimensions such that:
     in each row, each element of each column is equal to:</p>
  
  <pre><code>         0.4*[(Sum of all elements of that row of the development.costs table up until the year of the element) - (Sum of all elements of that row of the depreciation.costs table up until one year before)]
  </code></pre>
  
  <p>so I want to create a table</p>
  
  <p>a b c d<br>
  e f g h<br>
  i j k l </p>
  
  <p>such that e.g. c =0.4*[(1+2+3) - (a+b)]</p>
  
  <p>the code I managed to write is </p>
  
  <pre><code>for (y in Years)
  {depreciation.costs[y, ] &lt;- 0.4*(colSums(development.costs[1:y], )-colSums(depreciation.costs[1:(y-1), ]))}
  </code></pre>
  
  <p>where Years &lt;- 1:4</p>
  
  <p>but this is wrong since the system gives me the error</p>
  
  <p>Error in colSums(depreciation.rate[, 1:(y - 1)]) : 
    'x' must be an array of at least two dimensions</p>
  
  <p>many thanks for any feedback</p>