How do I sum the values of columns in several tables if tables have different lengths?

后端 未结 3 361
离开以前
离开以前 2021-01-17 23:35

Alright, this should be an easy one but I\'m looking for a solution that\'s as fast as possible.

Let\'s say I have 3 tables (the number of tables will be much larger

3条回答
  •  天涯浪人
    2021-01-18 00:17

    you can try this

    df <- rbind(as.matrix(tab1), as.matrix(tab2), as.matrix(tab3))
    aggregate(df, by=list(row.names(df)), FUN=sum)
      Group.1 V1
    1       1  7
    2       2  3
    3       3  4
    4       4  3
    5       5  1
    

提交回复
热议问题