I have the following dataframe:
df1 <- data.frame( id = c(1,2,2,3),
word = c("house, garden, flower", "flower, red", "garden, tree, forest", "house, window, door, red"),
value = c(10,12,20,5),
stringsAsFactors = FALSE
)
Now I want to consolidate rows based on id. So if there is a duplicated id, the values in column word should be merged and the column value should be summed up. This means the df should look like this:
id | word | value
1 | house, garden, flower | 10
2 | flower, red, garden, tree, forest | 32
3 | house, window, door, red | 5
Does anybody has an idea, how to solve this problem?