[R] coef(summary) and plyr

Hadley Wickham hadley at rice.edu
Mon Aug 9 16:50:45 CEST 2010


On Mon, Aug 9, 2010 at 9:29 AM, David Winsemius <dwinsemius at comcast.net> wrote:
> If you look at the output (as I did)  you should see that despite whatever
> expectations you have developed regarding plyr, that it did not produce a
> grouping variable:
>
>> ldply(dl, function(x) coef(summary(x)) )
>   fac    Estimate Std. Error     t value     Pr(>|t|)
> 1    0  -0.3563418  0.1438322   -2.477483 1.820555e-02
> 2    1   0.9197772  0.1525900    6.027768 7.097623e-07
> 3    2   3.0481679  0.1331307   22.896050 1.197920e-22
> 4    0 -18.7726473  0.1281064 -146.539553 2.125848e-50
> 5    1  -0.2961841  0.1885210   -1.571093 1.273942e-01
> 6    2   1.2846496  0.1833394    7.006946 1.277086e-07
> 7    0   2.9664816  0.1737222   17.076010 2.448612e-16
> 8    1 -18.7265068  0.2044723  -91.584567 3.048491e-36
> 9    2   0.3993073  0.1979713    2.016996 5.455569e-02
> 10   0   0.7657945  0.2477459    3.091048 4.846678e-03
> 11   1   3.0365005  0.1731814   17.533641 1.470033e-15
> 12   2 -19.2140081  0.1882448 -102.069256 2.741417e-34

cf.

> ldply(dl, coef)
  fac (Intercept)        x1       x2        x3
1   0 -0.12051346 1.1391933 3.022287 -19.01828
2   1 -0.08890497 1.0741715 3.219577 -19.14279
3   2 -0.12728421 0.9284263 2.973905 -19.12774

which you can see maintains the original grouping variable fac.

The problem is that summary stores the variable names as rownames,
which does not make for easy rbinding.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list