r - How to aggregate big data? -


i have big data set of sales data this:

  ordernumber     category   sold_items 1 123                      2 2 123             b          1 3 234             c          1 4 345             d          1 5 456                      2 6 456             b          1 

and want aggregate this:

    b   c   d     frequency   2   1             2           1         1               1     1  

so, want have 1 row every category-combination exists in sales data. , want know how frequent 1 combination is.

well, tried cast , melt , me there, when data set small enough. unfortunately, have >3 million rows of data cast , melt cannot handle more.

can tell me how aggregate data in fast way?

thank in advance!

you may try

library(data.table)#v1.9.5+ dcast(setdt(df1), ordernumber~category, value.var='sold_items')[,         frequency:=do.call(pmax, c(.sd, na.rm=true)), .sdcols=2:5] 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -