Merge rows with duplicate IDs

后端 未结 2 1336
礼貌的吻别
礼貌的吻别 2021-01-26 01:09

I would like to merge and sum the values of each row that contains duplicated IDs.

For example, the data frame below contains a duplicated symbol \'LOC102723897\'. I wou

2条回答
  •  日久生厌
    2021-01-26 01:30

    You group-by on Symbol and sum all columns.

    library(dplyr)
    df %>% group_by(Symbol) %>% summarise_all(sum)
    

    using data.table

    library(data.table)
     setDT(df)[ , lapply(.SD, sum),by="Symbol"]
    

提交回复
热议问题