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

后端 未结 3 359
离开以前
离开以前 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:33

    We concatenate (c) the tab output to create 'v1', use tapply to get the sum of the elements grouped by the names of that object.

    v1 <- c(tab1, tab2, tab3)
    tapply(v1, names(v1), FUN=sum)
    #1 2 3 4 5 
    #7 3 4 3 1 
    

提交回复
热议问题