What is the most efficient way to sum all columns whose name starts with a pattern?

后端 未结 4 1460
南旧
南旧 2021-01-11 14:37

My goal is to sum all values in columns that start with the prefix skill_ in a data.table. I would prefer a solution using data.table

4条回答
  •  自闭症患者
    2021-01-11 15:02

    Here is a dplyr solution:

    library(dplyr)
    
    DT %>% mutate(count = DT %>% select(starts_with("skill_")) %>% rowSums())
    

提交回复
热议问题