title: How to add sum rows of a table or matrix in R?
body: <p>I have a matrix in R, that looks like the following: </p>
  
  <pre><code>     [,1] [,2] [,3] [,4]
  [1,]    0   1     1    1
  [2,]    2   12   22   32
  [3,]    3   13   23   33
  [4,]    4   14   24   34
  [5,]    5   15   25   35
  [6,]    6   16   26   36
  [7,]    7   17   27   37
  [8,]    8   18   28   38
  [9,]    9   19   29   39
  [10,]   10   20   30   40
  </code></pre>
  
  <p>I want to add every two rows are together, so that [1,] and [2,], create a new vector (say A).  I need to do this repeatedly (so then [3,] and [4,] etc).  I need to do this in a loop or some other way if that is possible (my actual data has 49 columns and 1000 rows).  If possible, I would like it to create a new matrix with all the new data in, so from my original data I would have 500 rows, or here 5 rows?</p>
  
  <p>I have tried the following code:</p>
  
  <pre><code> dips = matrix()
   X &lt;- seq(1, by = 2, len = 1000)
   for(i in X)
   {
   dips[i] = population[i,] + population[i+1,]
  }
  </code></pre>
  
  <p>I keep getting a warning,  "number of items to replace is not a multiple of replacement length".  And the data produced doesn't contain all 49 columns. </p>
  
  <p>Sorry if this is a basic question or has already been solved, I am a beginner.   Thank you in advance! </p>