how do I search for columns with same name, add the column values and replace these columns with same name by their sum? Using R

后端 未结 4 668
情话喂你
情话喂你 2021-01-05 20:56

I have a data frame where some consecutive columns have the same name. I need to search for these, add their values in for each row, drop one column and replace the other wi

4条回答
  •  情深已故
    2021-01-05 21:27

    Here is my one liner

    # transpose data frame, sum by group = rowname, transpose back.
    t(rowsum(t(dfrm), group = rownames(t(dfrm))))
    

提交回复
热议问题