title: loop through all files in a directory, read and save them in an object R
body: <p>I need to loop through all files in a directory, read and save them in an object with the same name.</p>
  
  <p>I tried the following but none of them worked:</p>
  
  <pre><code>files &lt;- list.files(path=".", pattern="*.txt", all.files=T, full.names=T)
  
  lapply(files, function(x) {
  t &lt;- read.table(x, header=F)  
  out_x &lt;- function(t)            
  })
  </code></pre>
  
  <p>or </p>
  
  <pre><code>path = "."
  out.file&lt;-""
  file.names &lt;- dir(path, pattern ="*.txt") 
  for(i in 1:length(file.names)){
  file &lt;- read.table(file.names[i],header=TRUE)
  out.file &lt;- rbind(out.file, file)
  } 
  </code></pre>