On Mon, Aug 9, 2010 at 4:30 PM, Matthew Dowle <mdo...@mdowle.plus.com> wrote: > > > Another option for consideration : > > library(data.table) > mydt = as.data.table(mydf) > > mydt[,as.list(coef(lm(y~x1+x2+x3))),by=fac] > fac X.Intercept. x1 x2 x3 > [1,] 0 -0.16247059 1.130220 2.988769 -19.14719 > [2,] 1 0.08224509 1.216673 2.847960 -19.16105 > [3,] 2 0.02052320 1.135421 3.134154 -19.22555 > > mydt[,data.table(coef(summary(lm(y~x1+x2+x3))),keep.rownames=TRUE), by=fac] > fac rn Estimate Std..Error t.value Pr...t.. > [1,] 0 (Intercept) -0.16247059 0.1521507 -1.0678269 2.929087e-01 > [2,] 0 x1 1.13021985 0.1374020 8.2256414 1.079035e-09 > [3,] 0 x2 2.98876920 0.1404903 21.2738533 1.325909e-21 > [4,] 0 x3 -19.14719151 0.1335139 -143.4096890 4.520371e-50 > [5,] 1 (Intercept) 0.08224509 0.2360664 0.3483981 7.313719e-01 > [6,] 1 x1 1.21667349 0.2723201 4.4678058 2.637743e-04 > [7,] 1 x2 2.84796003 0.2232960 12.7541904 9.192555e-11 > [8,] 1 x3 -19.16104669 0.2394431 -80.0233818 1.707058e-25 > [9,] 2 (Intercept) 0.02052320 0.1902526 0.1078734 9.147302e-01 > [10,] 2 x1 1.13542085 0.1786333 6.3561559 2.980475e-07 > [11,] 2 x2 3.13415398 0.1894404 16.5442781 7.827178e-18 > [12,] 2 x3 -19.22554984 0.1708307 -112.5415605 2.536686e-45
That reminds me: library(reshape) ldply(dl, function(x) namerows(as.data.frame(coef(summary(x))))) I think both Matthew and I would agree that row names are a pain. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.