I would like to run a regression and store the coefficients in a data.table. Here is a minimal example:
library(data.table)
library(MASS)
dt <- as.data.table(iris)
dt[, c("coef1", "coef2") := rlm(Sepal.Length ~ Petal.Length)$coef]
dt
However it recycles the output so the coef1 and coef2 are the same on each line, but the two coefficients show up on every other line.
This example shows how I would like it to look, but it is not optimal because it requires running the regression twice:
dt <- as.data.table(iris)
dt[, `:=`("coef1"=rlm(Sepal.Length ~ Petal.Length)$coef[1], "coef2"=rlm(Sepal.Length ~ Petal.Length)$coef[2])]
dt