0

I'm experimenting with data.table's ability to hold lists - in this case the output of linear models

require(data.table)

ir <- data.table(iris)
setkey(ir, Species)

lm.mods <- ir[, list(mods=list(lm(Sepal.Length~Sepal.Width))), by="Species"]

I can access a single model

lm.mods[1 , summary(mods[[1]])]

But I can't work out how to create a new variable that is a list containing the summary of each model. I think it may require .SD or := but I can't work it out.

Any suggestions?

Ed G
  • 802
  • 1
  • 6
  • 19
  • `lm.mods[, mods.sum := lapply(mods, summary)]; lm.mods$mods.sum`? – Arun Dec 19 '13 at 11:25
  • Beware of the pitfalls mentioned here: http://stackoverflow.com/questions/15096811/why-is-using-update-on-a-lm-inside-a-grouped-data-table-losing-its-model-data/15376891#15376891 – mnel Dec 19 '13 at 11:38
  • @Arun, that does the job - thanks. I was trying various combinations of lm.mods[, mods.sum := summary(mods)] which wasn't working. – Ed G Dec 19 '13 at 11:39
  • @mnel, thank you - i'll bear that in mind – Ed G Dec 19 '13 at 11:42

0 Answers0