I have my data table in R. I want to merge rows which have an identical customerID, and then concatenate the elements of other merged columns.
I want to go from this:
title author customerID
1 title1 author1 1
2 title2 author2 2
3 title3 author3 1
to this:
title author Group.1
1 title1, title3 author1, author3 1
2 title2 author2 2
The
aggregatefunction should help you in finding a solution:Or, just make sure you add
stringsAsFactors = FALSEwhen you are creating your data frame and you’re pretty much good to go. If your data are already factored, you can use something likedat[c(1, 2)] = apply(dat[-3], 2, as.character)to convert them to character first, then: