title: How to merge a list of dataframes by a single column?
body: <p>I have a list of dataframes, each of which has a "Name" column and a "Sample" column.</p>
  
  <pre><code>df1:
  
  Name Sample1
  A 23
  B 445
  C 456
  
  df2:
  
  Name Sample2
  A 45
  B 984
  C 374
  </code></pre>
  
  <p>How can I merge all the dataframes in my list so they end up like so:</p>
  
  <pre><code>merged:
  
  Name Sample1 Sample2
  A 23 45
  B 445 984
  C 456 374
  </code></pre>
  
  <p>I have tried answers from similar questions on SO but none of them have produced the desired result. E.g. <code>merged.data.frame = Reduce(function(...) merge(..., all=T), list.of.data.frames)</code></p>
  
  <p>Edit:</p>
  
  <p>My original script is listed below</p>
  
  <pre><code># List all files in current working directory
  fs &lt;- list.files()
  
  # Load the data from each file into a list of data frames
  dfs &lt;- lapply(fs, read.table, header=TRUE, sep="\t")
  
  # Select only the Name and Concentration columns from the list of data frames
  dfs &lt;- lapply(dfs, subset, select=c(Name, Concentration))
  
  # Sort each dataframe alphabetically by the Name column
  dfs &lt;- lapply(dfs, function(df){df[order(df$Name),]})
  
  # Rename each Concentration heading with the basename of the filename where the data originates
  for (i in 1:length(dfs)){colnames(dfs[[i]])[2] &lt;- substr(fs[i], 1, nchar(fs[i]) - 4)}
  
  # Merge all the dataframes together by the Name column
  
  # Write merged dataframe out to a tab-delimited file
  write.table(dfs, ".", sep="\t")
  </code></pre>