title: Merging .txt files from 2002-2020 for bulk financial data into one table
body: <p>I am very new to R and RStudio and currently running codes from Machine Learning with R Quick Start Guide to review bulk financial data. I am running the following code chunk in R:</p>
  <pre><code>
  library(readr)
  
  t &lt;- proc.time()
  
  for (i in 1:length(myfiles)){
  
  tables&lt;-list() 
  myfiles &lt;- list.files(path = &quot;~/MachineLearning/Banks_model&quot;, pattern = &quot;20&quot;,  full.names = TRUE)
  
  filelist &lt;- list.files(path = myfiles[i], pattern = &quot;*&quot;,  full.names = TRUE)
  filelist&lt;-filelist[1:(length(filelist)-1)]
  
  for (h in 1:length(filelist)){
  
  #assuming tab separated values with a header    
  aux = as.data.frame(read_delim(filelist[h],  &quot;\t&quot;, escape_double = FALSE, col_names = FALSE, trim_ws = TRUE, skip = 2))
  
  variables&lt;-colnames(as.data.frame(read_delim(filelist[h],  &quot;\t&quot;, escape_double = FALSE, col_names = TRUE, trim_ws = TRUE, skip = 0)))
  
  colnames(aux)&lt;-variables
  
  dataset_name&lt;-paste(&quot;aux&quot;,h,sep='')
  tables[[h]]&lt;-assign(dataset_name,aux)
  
  }
  
  final_data_name&lt;-paste(&quot;year&quot;,i+2001,sep='')
  union &lt;- Reduce(function(x,y) merge(x, y, all=TRUE, 
      by=c(&quot;ID RSSD&quot;,&quot;Reporting Period&quot;)), tables, accumulate=FALSE)
  
  assign(final_data_name,union)
  rm(list=ls()[! ls() %in% c(ls(pattern=&quot;year*&quot;),&quot;tables&quot;,&quot;t&quot;)])
  }
  
  proc.time() - t 
  
  </code></pre>
  <p>and received the following error:</p>
  <p>Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns</p>
  <p>The traceback in RStudio is as follows:
  7.
  stop(ngettext(sum(bad), &quot;'by' must specify a uniquely valid column&quot;, &quot;'by' must specify uniquely valid columns&quot;), domain = NA)
  6.
  fix.by(by.x, x)
  5.
  merge.data.frame(x, y, all = TRUE, by = c(&quot;ID RSSD&quot;, &quot;Reporting Period&quot;))
  4.
  merge(x, y, all = TRUE, by = c(&quot;ID RSSD&quot;, &quot;Reporting Period&quot;))
  3.
  merge(x, y, all = TRUE, by = c(&quot;ID RSSD&quot;, &quot;Reporting Period&quot;))
  2.
  f(init, x[[i]])
  1.
  Reduce(function(x, y) merge(x, y, all = TRUE, by = c(&quot;ID RSSD&quot;, &quot;Reporting Period&quot;)), tables, accumulate = FALSE)</p>
  <p>Any idea what the fix is please?</p>