create a formula in a data.table environment in R
lm
can accept a character string as the formula so combine that with .SD
like this:
> x[, as.list(coef(lm("a ~ b", .SD))), by = id] id (Intercept) b1: 1 21 -12: 2 21 -13: 3 21 -14: 4 21 -15: 5 21 -1