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