title: How to append multiple files in R
body: <p>I'm trying to <strong>read a list of files and append them into a new file with all the records</strong>. I do not intend to change anything in the original files. I've tried couple of methods.</p>
  
  <p><strong>Method 1:</strong> This methods creates a new file but at each iteration the previous file gets added again. Because I'm binding the data frame recursively.</p>
  
  <pre><code>files &lt;- list.files(pattern = "\\.csv$")
  
    #temparary data frame to load the contents on the current file
    temp_df &lt;- data.frame(ModelName = character(), Object = character(),stringsAsFactors = F)
  
    #reading each file within the range and append them to create one file
    for (i in 1:length(files)){
      #read the file
      currentFile = read.csv(files[i])
  
      #Append the current file
      temp_df = rbind(temp_df, currentFile)    
    }
  
    #writing the appended file  
    write.csv(temp_df,"Models_appended.csv",row.names = F,quote = F)
  </code></pre>
  
  <p><strong>Method 2:</strong> I got this method from <a href="http://www.r-bloggers.com/merging-multiple-data-files-into-one-data-frame/" rel="noreferrer">Rbloggers</a> . This methods won't write to a new file but keeps on modifying the original file. </p>
  
  <pre><code>multmerge = function(){
    filenames= list.files(pattern = "\\.csv$")
    datalist = lapply(filenames, function(x){read.csv(file=x,header=T)})
    Reduce(function(x,y) {merge(x,y)}, temp_df)
  
  }
  </code></pre>
  
  <p>Can someone advice me on how to achieve my goal?</p>