title: How to add duplicated values in a matrix in R
body: <p>Starting from this sample matrix:</p>
  
  <pre><code> my.matrix &lt;- cbind(c('a','b','c','a','d','a','e','f','g','h','a'), c(1,1,1,1,2,2,2,2,3,4,4))
   my.matrix
           [,1] [,2]
   [1,] "a"  "1" 
   [2,] "b"  "1" 
   [3,] "c"  "1" 
   [4,] "a"  "1" 
   [5,] "d"  "2" 
   [6,] "a"  "2" 
   [7,] "e"  "2" 
   [8,] "f"  "2" 
   [9,] "g"  "3" 
   [10,] "h"  "4" 
   [11,] "a"  "4" 
  </code></pre>
  
  <p>Is there a way of adding the numerical values of every repeated letter? so that the final result would be:</p>
  
  <pre><code>cbind(c('a','b','c','d','e','f','g','h'), c(7,1,1,2,2,2,3,4))
      [,1] [,2]
  [1,] "a"  "7" 
  [2,] "b"  "1" 
  [3,] "c"  "1" 
  [4,] "d"  "2" 
  [5,] "e"  "2" 
  [6,] "f"  "2" 
  [7,] "g"  "3" 
  [8,] "h"  "4" 
  </code></pre>