title: Changing Column Names in a List of Data Frames in R
body: <p>Objective: Change the Column Names of all the Data Frames <strong>in the Global Environment</strong> from the following list</p>
  
  <p>colnames of the ones in global environment</p>
  
  <p>So. </p>
  
  <p>0) The Column names are:</p>
  
  <pre><code> colnames = c("USAF","WBAN","YR--MODAHRMN") 
  </code></pre>
  
  <p>1) I have the following data.frames: df1, df2. </p>
  
  <p>2) I put them in a list: </p>
  
  <pre><code>  dfList &lt;- list(df1,df2)
  </code></pre>
  
  <p>3) Loop through the list:</p>
  
  <pre><code> for (df in dfList){
     colnames(df)=colnames
   }
  </code></pre>
  
  <p>But this creates a new df with the column names that I need, it doesn't change the original column names in df1, df2. Why? Could lapply be a solution? Thanks</p>
  
  <p>Can something like:</p>
  
  <pre><code> lapply(dfList, function(x) {colnames(dfList)=colnames})
  </code></pre>
  
  <p>work?</p>