I want to merge rows together that have the same word in another column. The table entries are all comma separated strings (characters), not lists. So as shown below the color shades for the same color should be added in a string in one row, instead of spanning over several rows. Also there should be no duplicates in the color shades column.
I have already tried with:
aggregate(df["Color shades"], df["Color"], paste, collapse=", ")
As well as with:
aggregate(Color shades ~ Color ,df ,toString)
But that didn't lead to the desired result.
Dataframe:
df <- data.frame(colorshades = c("turquoise, babyblue", "royal blue, true blue",
"navy blue, true blue"), colors = c("blue", "blue", "blue"))
Currently:
| Color shades | Color |
|---|---|
| turquoise, babyblue | blue |
| royal blue, true blue | blue |
| navy blue, true blue | blue |
Desired Output:
| Color shades | Color |
|---|---|
| turquoise, babyblue, royal blue, true blue, navy blue | blue |