Sort a data.table fast by Ascending/Descending order

后端 未结 2 465
说谎
说谎 2020-11-30 21:38

I have a data.table with about 3 million rows and 40 columns. I would like to sort this table by descending order within groups like the following sql mock code:

<         


        
2条回答
  •  野性不改
    2020-11-30 21:44

    The comment was mine, so I'll post the answer. I removed it because I couldn't test whether it was equivalent to what you already had. Glad to hear it's faster.

    X <- X[order(Year, MemberID, -Month)]
    

    Summarizing shouldn't depend on the order of your rows.

提交回复
热议问题