title: collapse into single row without concatenation
body: <p>I have DF as follows:</p>
  <pre><code>                 df &lt;- structure(list(RID = c(1L, 1L, 2L, 2L, 3L, 3L), 
                   Sex = c(&quot;FEMALE&quot;, &quot;FEMALE&quot;, &quot;MALE&quot;, &quot;MALE&quot;, &quot;FEMALE&quot;, &quot;FEMALE&quot;),
                   Race = c(&quot;White&quot;,&quot;White&quot;, &quot;Hispanic&quot;, &quot;Hispanic&quot;, &quot;Black&quot;, &quot;Black&quot;),
                   TIME = c(&quot;Break Fast&quot;, &quot;Break Fast&quot;, &quot;Lunch&quot;, &quot;Lunch&quot;, &quot;Dinner&quot;, &quot;Dinner&quot;),
                   Sugar = c(&quot;Normal&quot;, &quot;Normal&quot;, &quot;Abnormal&quot;, &quot;Abnormal&quot;, &quot;Satisfactory&quot;, 
                   &quot;Satisfactory&quot;), 
                   Test_A = c(90L,&quot;&quot;,&quot;&quot; , 157L,&quot;&quot; , 129L),
                   Test_B = c(&quot;&quot;,90L , 157L,&quot;&quot;, 129L,&quot;&quot; )),
                   class = &quot;data.frame&quot;, row.names = c(NA, -6L))
  </code></pre>
  <p>The required output is:</p>
  <pre><code>                 Requd_df &lt;- structure(list(RID = c(1L, 2L,3L), 
                   Sex = c(&quot;FEMALE&quot;, &quot;MALE&quot;, &quot;FEMALE&quot;),
                   Race = c(&quot;White&quot;, &quot;Hispanic&quot;,&quot;Black&quot;),
                   TIME = c(&quot;Break Fast&quot;,  &quot;Lunch&quot;,   &quot;Dinner&quot;),
                   Sugar = c(&quot;Normal&quot;,  &quot;Abnormal&quot;,  &quot;Satisfactory&quot;), 
                   Test_A = c(90L, 157L, 129L),
                   Test_B = c(90L , 157L, 129L)),
                   class = &quot;data.frame&quot;, row.names = c(NA, -3L))
  </code></pre>
  <p>My code is as follows:</p>
  <pre><code>                 setDT(df)
  
                   df1 &lt;-  df[, lapply(.SD, paste0, collapse=&quot;&quot;), by= RID]
  </code></pre>
  <p>My code is concatenating every element of columns - RID, Sex,Race,Time,Sugar.
  Need to collapse without concatenation
  Please help</p>