R collapse multiple rows into 1 row - same columns
<p>This is piggy backing on a question I answered last night as I am reconsidering how I'd like to format my data. I did search but couldn't find up with any applicable answer; I may be searching with wrong terms.</p>

<p>I have a data table with many rows that I'd like to combine:</p>

<pre><code>record_numb &lt;- c(1,1,1,2,2,2)
col_a &lt;- c(123,'','',987,'','')
col_b &lt;- c('','234','','','765','')
col_c &lt;- c('','','543','','','543')
df &lt;- data.frame(record_numb,col_a,col_b,col_c)
library(data.table)
setDT(df)

record_numb    col_a    col_b     col_c
1               123
1                       234
1                                 345
2               987
2                       765
2                               543
</code></pre>

<p>Each row will always have either col_a, col_b, or col_c populated. It will never have more than 1 of those 3 populated. I'd like to pivot(?) these into a single row per record so it appears like this:</p>

<pre><code>record_numb     col_a   col_b   col_c
1               123     234     345
2               987     765     543
</code></pre>

<p>I played with melt/cast a bit, but I'm such a novice at R that half of my issue is knowing what is available to use. There is just so much to use that I'm hoping one of you can point me to a package or function off the top of your head. My searches I performed pointed me to melt and cast and such, but I was unable to apply it to this case. I'm open to using any function or package.</p>