Row sums over columns with a certain pattern in their name

后端 未结 3 1326
梦毁少年i
梦毁少年i 2020-12-03 01:33

I have a data.table like this

dput(DT)
structure(list(ref = c(3L, 3L, 3L, 3L), nb = 12:15, i1 = c(3.1e-05, 
0.044495, 0.82244, 0.322291), i2 = c(0.000183, 0.1         


        
3条回答
  •  一生所求
    2020-12-03 01:48

    The dplyr solution would be to use mutate_ together with paste(listCol, collapse = "+"). But I guess the Reduce solution is faster.

    DT <- mutate_(DT, sum = paste(listCol, collapse = "+"))
    

提交回复
热议问题