I have a data frame that that has unique names in one column with tons of variable names in a sister column. It kind of looks a little like this. Sorry it's not perfect.
df <- data.frame("Unit" = c("Unit1", "Unit1", "Unit1", "Unit2", "Unit2", "Unit3", "Unit3", "Unit3", "Unit3"),"Reg" = c("Reg1", "Reg2", "Reg3"))
The real data looks like this:
Unit_Name;Reg_Name
Unit1;Reg_ABC
Unit1;Reg_XYZ
Unit1;Reg_DEF
Unit2;Reg_ABC
Unit2;Reg_DEF
Unit3;Reg_XYZ
Unit3;Reg_ABC
What I want to get is a new column that collapses Reg_Name next to the unique Unit_Name with the Reg_Names concatenated with a semi-colon:
Unit_Name | Reg_Name
Unit_1 | Reg_ABC;Reg_XYZ;Reg_DEF
Unit_2 | Reg_DEF;Reg_ABC;Reg_DEF
Unit_3 | Reg_XYZ; Reg_ABC
I've tried twenty different solutions in R but none of them actually seem to address this exact issue and the ones that are close are dealing with different desired outcomes.