I have a dataframe with different variables that can share some factor levels:
id tag_1 tag_2 tag_3
1: 3 human NA artist
2: 5 human NA NA
3: 7 song artist human
4: 8 town human NA
As you can see, "human" level is present in three different variables (tag_1, tag_2 and tag_3), and level "artist" in two variables (tag_2 and tag_3).
Knowing that each factor level is unique in a given row, I would like to group same levels into the same column, in order to have exclusive factor levels in each column:
id tag_1 tag_2 tag_3
1: 3 human NA artist
2: 5 human NA NA
3: 7 human song artist
4: 8 human town NA
Is there a way to do so?
If not the alternative would be to sort in each row the levels by occurrences (occurrences within all dataframe)...
Thanks for any brilliant idea!