R programming (extract same element matched with first column) : <p>I have below list:</p>

<blockquote>
  <p>head(input)</p>
</blockquote>

<pre><code>   V1 V2 V3 V4 V5 V6

1  A  1  2  3  4  5

2  B  1  2 NA NA NA

3  C  3  5 NA NA NA

4  D  3 NA NA NA NA

5  E  4  5  6  1  8
</code></pre>

<p>and I would like to get below results (extract all V1 elements matches to unique element from V2~V6):</p>

<pre><code>1   A   B   E

2   A   B   

3   A   C   D

4   A   E   

5   A   C   E

6   E       

8   E
</code></pre>

<p>I was trying to write code in R, but I keep getting errors.. Can you please help with this code?</p>

<p>Thank you in advance.</p>
