R- Collapse rows and sum the values in the column

后端 未结 5 726
情话喂你
情话喂你 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条回答
  •  灰色年华
    2021-02-06 03:33

    Example using dplyr, the next iteration of plyr:

    df2 <- df1 %>% group_by(ID) %>%
         summarize(Sum_PSM = sum(PSM))
    

    When you put the characters %>%, you are "piping." This means you're inputting what is on the left side of that pipe operator and performing the function on the right.

提交回复
热议问题