Merging two matrices of different size in R
<p>I've seen a few questions asked about this, but I wasn't able to understand any of the answers and they all seem to be closed threads.</p>

<p>What I'm looking to do is to merge two matrices which have one common column but the other columns are different and the row number is significantly different. I should merge the two matrices in one by checking if any row has a matching column value of the common column.</p>

<p>For example: Matrix 1</p>

<pre><code>Matrix 1
Col1 Col2 Col3 Col4
a     b    c    d
e     f    g    h
i     j    k    l

Matrix 2
Col1 Col5
a    e
g    f
</code></pre>

<p>In the above example, the first row in Matrices 1 and two have the same entries in Col1 and Col3, while rows 2 and 3 are dissimilar.</p>

<p>I would like the output to look as follows:</p>

<pre><code>NewMatrix
Col1 Col2 Col3 Col4 Col5
a     b   c    d    e
e     f   g    h    NA
i     j   k    l    NA
g     NA  NA    NA   f
</code></pre>

<p>So that the matching rows are joined, while any rows that don't match are simply added on to the end.</p>

<p>Would anyone have an idea of how to do this?</p>