title: Merging multiple two-column text files into one data frame based on one column
body: <p>This question is a follow-up to <a href="https://stackoverflow.com/questions/34201849/merge-join-several-tables-unix-linux">this one</a>, which got negative responses and no answers. So, I'm trying to do this using R.</p>
  
  <p>I have many (more than 30) files like this:</p>
  
  <ul>
  <li><p>File1</p>
  
  <pre><code>5 A1
  23 A3
  1 B2
  289 BX5
  90 D3
  </code></pre></li>
  <li><p>File2</p>
  
  <pre><code>2 A1
  10 A2
  3 B1
  1 BX4
  90 D3
  24 E0
  </code></pre></li>
  <li><p>File3</p>
  
  <pre><code>4 A0
  11 A2
  1 B1
  2 D3
  </code></pre></li>
  </ul>
  
  <p>And I would like to combine all of them to produce a data frame like this:</p>
  
  <pre><code>A0 0 0 4
  A1 5 2 0
  A2 0 10 11
  A3 23 0 0
  B1 0 3 1
  B2 1 0 0
  BX4 0 1 0
  BX5 289 0 0
  D3 90 90 2
  E0 0 24 0
  </code></pre>
  
  <p>Based on <a href="https://stackoverflow.com/a/7739757/4896390">this</a>, I tried to read two files using read.table while specifying the second column as the row names and then I merged the data frames by row names, like this:</p>
  
  <pre><code>&gt; df1 &lt;- read.table("File1", row.names = 2)
  &gt; df1
       V1
  A1    5
  A3   23
  B2    1
  BX5 289
  D3   90
  &gt; df2 &lt;- read.table("File2", row.names = 2)
  &gt; df2
       V1
  A1    2
  A2   10
  B1    3
  BX4   1
  D3   90
  E0   24
  &gt; m1 &lt;- merge(df1, df2, by=0, all=TRUE)
  &gt; m1[is.na(m1)] &lt;- 0
  &gt; m1
      Row.names V1.x V1.y
  1          A1    5    2
  2          A2    0   10
  3          A3   23    0
  4          B1    0    3
  5          B2    1    0
  6         BX4    0    1
  7         BX5  289    0
  8          D3   90   90
  9          E0    0   24
  </code></pre>
  
  <p>So far so good, but when I tried to merge the resulting data frame to the third one, it doesn't work as I hoped for. And because of that, I'm not sure how I will continue to merge all the 30-something files into one data frame. Previously I thought I would modify the <code>multmerge</code> function described <a href="http://www.r-bloggers.com/merging-multiple-data-files-into-one-data-frame/" rel="nofollow noreferrer">here</a>, but now I'm stuck.</p>
  
  <p>So, would anybody please help me with this? Thanks in advance.</p>
  
  <p>EDIT: I would also really appreciate if anyone could suggest me a better title for this question.</p>