R- Collapse rows and sum the values in the column

后端 未结 5 720
情话喂你
情话喂你 2021-02-06 02:46

I have the following dataframe (df1):

ID    someText    PSM OtherValues
ABC   c   2   qwe
CCC   v   3   wer
DDD   b   56  ert
EEE   m   78  yu
FFF           


        
5条回答
  •  梦毁少年i
    2021-02-06 03:32

    In base:

    aggregate(PSM ~ ID, data=x, FUN=sum)
    ##    ID PSM
    ## 1 ABC   2
    ## 2 CCC  58
    ## 3 DDD  56
    ## 4 EEE  80
    ## 5 FFF   1
    ## 6 GGG  90
    ## 7 KOO  45
    ## 8 LLL   4
    ## 9 ZZZ   8
    

提交回复
热议问题