title: Rename dataframe columns by string matching in R
body: <p>I am looping through a series of ids, loading 2 csvs for each, and applying some analysis to them. I need rename the columns of one of the 2 csvs to match the row values of the other. I need to do this inside the loop in order to apply it to the csvs for every id. </p>
  
  <p>I have tried renaming the columns like this: </p>
  
  <pre><code>`names(LCC_diff)[2:length(LCC_diff)] &lt;- c("Bare.areas" = "Bare areas",
  "Tree." = "Tree ", "Urban.areas" = "Urban areas", 
  "Water.bodies" = "Water bodies")`
  </code></pre>
  
  <p>where LCC_diff is a dataframe and the first value in each pair is the original column name and the second is the name that i want to assign to that column, but it just replaces the column names in order, and does not match them. </p>
  
  <p>This is a problem because not all column names need replaced, and the csvs for different ids have these columns in different orders. </p>
  
  <p>How do I match the original column names to the strings that I want to use to replace them?</p>