I have the following data frame in R:
objects categories
A 162
B 162
B 190
C 123
C 162
C 185
C 190
C 82
C 191
D 185
As you see there are objects and the categories they belong to. I would like to sum up the categories of each object in comma separated list to get a data frame which would look like this:
objects categories
A 162
B 162, 190
C 123, 162, 185, 190, 82, 191
D 185
How could I do this?
This can be done with any of the aggregation tools of your choice, I'll show an example using
plyr
package andpaste()
function. This assumes your data is namedx
:aggregate If
DF
is your data frame then try this:sqldf With sqldf this works:
As the title of your question implies, use
aggregate
:A
data.table
solution