title: Extracting specific column of different files and put them together in one big file in R
body: <p>I have 100 files, of which I want to extract the 4th column (total_volume) containing 100.000 rows and put it together in 1 big file which then contains 100 columns with each 100.000 rows. I was trying something with the following script:</p>
  
  <pre><code>setwd("/run/media/mydirectory")
  library(data.table)
  fileNames &lt;- Sys.glob("*.txt.csv")
  #read file in fileNames
  for (fileName in fileNames) {
  dataDf &lt;- read.delim(fileName, header = FALSE) 
  # remove columns with only example values 
  dataDf &lt;- dataDf[, -(7:14)] 
  # convert data frame to data table 
  dataDt &lt;- data.table(dataDf)
  # set column names
  setnames(dataDt, c("mcs", "cell_type", "cell_number", "total_volume"))
  #new file with only total volume
  total_volume &lt;- dataDt$total_volume
  #export file
  write.table(dataDt$total_volume, file = "total_volume20.csv")
  </code></pre>
  
  <p>But what I get then is that all columns get superimposed with as result a .csv file with the 4th column of only the last file. I would like the columns to be next to eachother instead of being superimposed. How could I do that? 
  Thanks in advance!</p>
  
  <p>P.S. Obviously the overwriting thing happens because I used a loop. However, I am not sure how else to combine everything, so suggestions are very welcome!</p>