Using dplyr/accross is very easy to summarize numeric variables which group by character variables (no need input variable names). Across can use to data.table but the speed will slow (just as manipulate dataframe ) .
Is the any way for not lost speed and convenience ? Thanks!
library(data.table)
library(dplyr)
test_data <- data.table(x=c('a','b','c','a','b','c'),y=c('d','e','f','d','e','f'),a=c(1:6),b=c(1,7,NA,3,5,6),c=c(NA,3,NA,4,7,8))
test_data %>% group_by(across(where(is.character))) %>%
summarise(across(where(is.number),function(x) sum(x,na.rm=TRUE)))