title: How to rename mutliples columns names (with prefix) according to respective dataframe name [R]
body: <p>I have 15 dataframes, that I have merged together. <a href="https://i.stack.imgur.com/TcOYW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TcOYW.png" alt="15 dataframe" /></a></p>
  <ol>
  <li>Here I'm loading my files.</li>
  </ol>
  <pre><code>data_files &lt;- list.files()  # Identify file names
                         
  
  for(i in 1:length(data_files)) {                              
    assign(paste0(substr(data_files[i],1,nchar(data_files[i])-4)),             
             read_excel(paste0(&quot;&quot;,
                             data_files[i])))
  }
  </code></pre>
  <p>Problem, they have the same columns names. That's why i want to rename the columns with the following code :</p>
  <pre><code>colnames(COMMUNITY)
   [1] &quot;OBJECTID&quot;                   &quot;SOURCE_ID&quot;                  &quot;mean&quot;                       &quot;LMiIndex Fixed 450000 RS&quot;  
   [5] &quot;LMiZScore Fixed 450000 RS&quot;  &quot;LMiPValue Fixed 450000 RS&quot;  &quot;COType Fixed 450000 RS&quot;     &quot;NNeighbors Fixed 450000 RS&quot;
   [9] &quot;ZTransform Fixed 450000 RS&quot; &quot;SpatialLag Fixed 450000 RS&quot;
  
  colnames(COMMUNITY) &lt;-paste(&quot;PREFIX&quot;,colnames(COMMUNITY),sep=&quot;-&quot;)
    
  </code></pre>
  <p>I would like to do this to my 15 dataframes, so I tried this :</p>
  <pre><code>List_df_EU = list(COMMUNITY,CSR_STRATEGY, EMISSIONS,ENV_PILLAR,ESGCOMBINED,ESGCONTROVERSIES,
                    ESGSCORE,GOV_PILLAR,HUMANRIGHTS,INNOVATION,MANAGEMENT,PRODUCT_RESP, RESSOURCE_USE, SOC_PILLAR, WORKFORCE)
  
  
  for(i in 1:length(List_df_EU)) {                              
    colnames(List_df_EU[i]) &lt;-paste(&quot;AS&quot;,colnames(List_df_EU[i]),sep=&quot;_&quot;)
    
  }
  </code></pre>
  <p>It doesn't work, and, <strong>I don't know how to retrieve dataframe name, in order to put him as PREFIX of columns.</strong><br />
  I could do it for each dataframe seperately, but it would take a long time, and would not be very clever.
  Even after many web researches, I never found something that was automated.</p>
  <p>After that, I use the following line of code to merge, It actually works, but as expected every colnames are identical.</p>
  <pre><code>Merged_file &lt;- purrr::reduce(List_df_EU, dplyr::left_join, by = 'OBJECTID', suffix = c(&quot;.x&quot;, &quot;.y&quot;))
  </code></pre>