title: Sum and replace columns with same name R for a data frame containing different classes
body: <p>I have a data frame containing multiple classes, I would like to sum those columns that have the same name and are numeric, and replace the old columns with the new sum, does anyone know a way to do this?</p>
  
  <p>i.e I have a data frame like:</p>
  
  <pre><code>col1 col2  col3 col3 
  char factor int int
  </code></pre>
  
  <p>I would like to produce</p>
  
  <pre><code>col1  col2  col3 
  char factor 2int
  </code></pre>
  
  <p>I have previously used:</p>
  
  <pre><code>data &lt;- as.data.frame(do.call(cbind, by(t(data),INDICES=names(data),FUN=colSums)))
  </code></pre>
  
  <p>However this was on a dataframe that only had numeric variables. </p>
  
  <p>There are other examples on the internet but not meeting the conditions of: replacement, preserving the rest of the frame, and of being on a frame with multiple classes</p>
  
  <p>Similar question: <a href="https://stackoverflow.com/questions/5938491/how-do-i-search-for-columns-with-same-name-add-the-column-values-and-replace-th">how do I search for columns with same name, add the column values and replace these columns with same name by their sum? Using R</a></p>