title: Averaging rows by columns with the same name
body: <p>I have a dataframe that is 130 rows by 1321 columns. Most of the column names are combinations of Month_Year (i.e. 1_89, 3_00, etc.). There are between 2-5 columns with the same name. I want to average the values in the rows in the columns with the same names. Here is my df structure:</p>
  
  <pre><code>    'data.frame':   130 obs. of  1321 variables:
      $ StationID: int  15 90 91 27 77 72 43 53 67 127 ...
      $ X        : num  -125 -124 -124 -124 -124 ...
      $ Y        : num  42.8 40.7 40.7 40.6 40.9 ...
      $ 1_89     : num  101 100 100 100 100 ...
      $ 1_89     : num  95.8 97.2 97.2 100 99 ...
      $ 1_89     : num  137 159 159 175 168 ...
      $ 1_89     : num  141 171 171 180 178 ...
      $ 1_89     : num  106 112 112 113 111 ...
      $ 2_89     : num  140 165 165 171 172 ...
      $ 2_89     : num  109 133 133 147 137 ...
      $ 2_89     : num  140 179 179 174 173 ...
      $ 2_89     : num  126 130 130 118 130 ...
      $ 3_89     : int  0 0 0 0 0 0 0 0 0 0 ...
      $ 3_89     : num  100 104 104 100 100 ...
      $ 3_89     : int  0 0 0 0 0 0 0 0 0 0 ...
      $ 3_89     : num  112 173 173 173 168 ...
      $ 4_89     : num  125 175 175 176 170 ...
      $ 4_89     : num  104 166 166 161 161 ...
      $ 4_89     : num  0 0 0 0 0 0 0 0 0 0 ...
  </code></pre>
  
  <p>I am aware that this is quite an unusual structure for a dataframe but I would like to convert this to a dataframe that looks like this:</p>
  
  <pre><code>    $ StationID: int  15 90 91 27 77 72 43 53 67 127 ...
      $ X        : num  -125 -124 -124 -124 -124 ...
      $ Y        : num  42.8 40.7 40.7 40.6 40.9 ...
      $ 1_89     : num  101 100 100 100 100 ...
      $ 2_89     : num  109 133 133 147 137 ...
      $ 3_89     : num  100 104 104 100 100 ...
      $ 4_89     : num  104 166 166 161 161 ...
  </code></pre>
  
  <p>but with average for each Month_Year. Thanks in advance for any help! </p>