title: Loop rename variables in R with assign()
body: <p>I am trying to rename a variable over several data frames, but assign wont work. Here is the code I am trying</p>
  
  <pre><code>assign(colnames(eval(as.name(DataFrameX)))[[3]], "&lt;- NewName")
  # The idea is, go through every dataset, and change the name of column 3 to
  # "NewName" in all of them
  </code></pre>
  
  <p>This won't return any error (All other versions I could think of returned some kind of error), but it doesn't change the variable name either. </p>
  
  <p>I am using a loop to create several data frames and different variables within each, now I need to rename some of those variables so that the data frames can be merged in one at a later stage. All that works, except for the renaming. If I input myself the names of the dataframe and variables in a regular call with <code>colnames(DF)[[3]] &lt;- "NewName"</code>, but somehow when I try to use assign so that it is done in a loop, it doesn't do anything. </p>