title: rename the multiple columns in R
body: <p>I have 1000 files with column similar column names.for example :</p>
  
  <p>df1                    </p>
  
  <pre><code>DATE PRICE CLOSE           
  </code></pre>
  
  <p>df2</p>
  
  <pre><code>DATE PRICE CLOSE 
  </code></pre>
  
  <p>and so on...</p>
  
  <p>If I try to merge them based by date they do get merge but the columns have retained their old names and I want to rename them in a loop</p>
  
  <p>so merge data set looks like this </p>
  
  <pre><code>Date Price Close PRICE CLOSE
  </code></pre>
  
  <p>I want something like</p>
  
  <pre><code>DATE PRICE1 CLOSE1 PRICE2 CLOSE2.
  </code></pre>
  
  <p>Is there any easy way to do it?
  I have tried couple of things which is not giving me correct output</p>
  
  <p>this is using plyr package:</p>
  
  <pre><code>mod_join = function(mypath){
    filenames=list.files(path=mypath, full.names=TRUE)
    datalist = lapply(filenames, function(x){read.csv(file=x,header=T)[,c('Date','High','Low')]})
    join_all(datalist,by = "Date")
  } 
  </code></pre>
  
  <p>this is using merge command on all data frame:</p>
  
  <pre><code>merge2 = function(mypath){
    filenames=list.files(path=mypath, full.names=TRUE)
    datalist = lapply(filenames, function(x){read.csv(file=x,header=T)[,c('Date','High','Low')]})
    Reduce(function(x,y) {merge(x,y,by.x= "Date",by.y = "Date",all=T)}, datalist)}
  
  }  
  </code></pre>
  
  <p>I tried using for loop by making the data frame lead then using each data frame to subset and merge subsequently but somehow its not subsetting the dataframes:</p>
  
  <pre><code>for (i in 1:1000){
    data_subset &lt;- sprintf('data_%d',i)
    mydata_subset &lt;- data.frame(,data_subset["Date"],data_subset["High"],data_subset["DayLow"])
    obj_name &lt;- paste('subset_Pricedata',i,sep ="_")
    assign(obj_name,value = mydata_subset)
  } 
  </code></pre>
  
  <p>Any help will be great.
  Thanks</p>