I have the following tibble,
contact <- tribble(
~name, ~phone, ~email,
'John', 123, '[email protected]',
'John', 456, '[email protected]',
'John', 456, '[email protected]',
'John', 789, '[email protected]'
)
I'd like to combine the phone numbers and emails if phone or email are the same, the desired output is the following,
contact_combined <- tribble(
~name, ~phone, ~email,
'John', '123;456', '[email protected];[email protected]',
'John', '789', '[email protected]'
)
I've tried grouping it first by name and phone and then by name and emails but it's not giving me the expected results. I'm stuck on finding an algorithmic way to solve this problem, could someone please give me an advice?
Note: The collapsing of the values in a column is not the question here. It's about selecting the records for the collapsing.