title: How to calculate the mean of those columns in a data frame with the same column name
body: <p>I have a data frame consisting of 10299 observations of 66 variables. Some of these variables share a common column name, and I would like to calculate the mean of those variables for each observation.</p>
  
  <p>Having the following matrix, with column names <code>c(A, B, C, B, A ,C)</code>:</p>
  
  <pre><code>A B C B A C                             
  1 2 3 4 5 6         
  3 5 6 7 4 3                             
  3 3 3 3 5 5                             
  2 2 2 2 2 2
  </code></pre>
  
  <p>I would like to get:                              </p>
  
  <pre><code>A   B   C    
  3   3   4.5
  3.5 6   4.5
  4   3   4
  2   2   2
  </code></pre>
  
  <p>I tried for loops, the command <code>aggregate()</code> but I don't get the desired result.</p>
  
  <p>Sorry if the question seems too basic, I have checked google for possible solutions but I didn't find any.</p>