title: Combine character strings into a single string by group in R
body: <p>I have data that looks like this:</p>
  <pre><code>library(dplyr)  
  
  Input &lt;- tibble(
        UID = c(&quot;Code001&quot;, &quot;Code001&quot;,&quot;Code002&quot;,&quot;Code002&quot;,&quot;Code002&quot;,&quot;Code002&quot;,&quot;Code003&quot;,&quot;Code003&quot;,&quot;Code003&quot;,&quot;Code004&quot;,&quot;Code005&quot;,&quot;Code005&quot;),
        Name = c(&quot;NameABC&quot;, &quot;Name JHB&quot;, &quot;NameYDB&quot;, &quot;Name &amp; KBC&quot;,&quot;Name-S-D-T&quot;, &quot;Name DF-R&quot;,&quot;NameMEY&quot;, &quot;Name PeU&quot;,&quot;Name Eed&quot;, &quot;NameBOR&quot;, &quot;Name-Ptg&quot;,&quot;NameLKD&quot;)) 
  </code></pre>
  <p>For each of the unique <code>UID's</code> I would like to combine the <code>Name</code> values into a single string. If there are two entries for the UID I would like an &amp; to separate them. If it is more than 2, then a comma to separate with an &amp; for the last two. I would like to create a new df that looks like this:</p>
  <pre><code>Output &lt;- tibble(
        UID = c(&quot;Code001&quot;, &quot;Code002&quot;,&quot;Code003&quot;,&quot;Code004&quot;,&quot;Code005&quot;),
        Name = c(&quot;NameABC &amp; Name JHB&quot;, &quot;NameYDB, Name &amp; KBC, Name-S-D-T &amp; Name DF-R&quot;, &quot;NameMEY, Name PeU &amp; Name Eed&quot;, &quot;NameBOR&quot;, &quot;Name-Ptg &amp; NameLKD&quot;)) 
  </code></pre>