In this toy example, I want to "sumproduct" a list of coefficients with each row's respective value and assign the result to a new column. The code below works for a given record, but when I remove the i parameter it behaves unexpectedly to me. I could do this in a loop or apply, but it seems like there's a data.table way that I'm missing.
DT <- data.table(mtcars)
vars <- c("mpg","cyl","wt")
coeffs <- c(2,3,4)
DT[1,Calc := sum(coeffs*DT[1,vars,with=FALSE])] # row 1 is assigned 70.480
DT[,Calc := sum(coeffs*DT[,vars,with=FALSE])] # all rows assigned 2830.416