Reshaping a column into rows, based on equality of corresponding column
<p>I am trying to reshape a dataframe in which subsequent cells that have the equal corresponding values on another column should be transitioned into a new dataframe or matrix with them in the same row, but in different cells.</p>

<p>As an example for the mechanism, the dataframe <code>df</code></p>

<pre><code>df &lt;- data.frame(PATID=c(1,2,2,3,3,3), SUB = c("5A", "2A", "2B", "1A", "2A", "2Y"))

PATID   SUB 
    1    5A 
    2    2A 
    2    2B 
    3    1A 
    3    2A 
    3    2Y
</code></pre>

<p>should be transformed into</p>

<pre><code>5A 
2A 2B
1A 2A 2Y
</code></pre>

<p>With in this case three rows (= # of unique values in <code>df$PATID</code>) and three columns but this should be scalable.</p>

<p>After searching, I have not found any equivalent question.</p>