Suppose a data.table:
z = data.table(k=1:10, h=1:100, i=1:100)
setkey(z, k)
I want to estimate for each key k, lm(h~i).
My first thought was just to try:
result = z[,lm(h~i),by=key(z)]
But this returns an error, reminding me, 'All items in j=list(...) should be atomic vectors or lists.'
Next, following the error's suggestion:
result = z[,list(lmcol=lm(h~i)),by=key(z)]
But,
result[1,class(lmcol[[1]])]
returns 'numeric' instead of 'lm'!
What is the correct procedure for recovering the entire lm object from the second code block?
Thanks!