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
Warning message:
In data.frame(..., check.names = FALSE) :
row names were found from a short variable and have been discarded
--
David
On Aug 9, 2010, at 10:11 AM, moleps wrote:
ldply doesnt need a grouping variable as far as I understand the
command..
"Description
For each element of a list, apply function then combine results into
a data frame
Usage
ldply(.data, .fun = NULL, ..., .progress = "none")"
regards,
M
On 9. aug. 2010, at 15.33, David Winsemius wrote:
On Aug 9, 2010, at 7:51 AM, moleps wrote:
Dear all,
I´m having trouble getting a list of regression variables back
into a dataframe.
mydf <- data.frame(x1=rnorm(100), x2=rnorm(100), x3=rnorm(100))
mydf$fac<-factor(sample((0:2),replace=T,100))
mydf$y<- mydf$x1+0.01+mydf$x2*3-mydf$x3*19+rnorm(100)
dlply(mydf,.(fac),function(df) lm(y~x1+x2+x3,data=df))->dl
here I´d like to use
ldply(dl,coef(summary)) or something similar but I cant figure it
out...
dfdl <- ldply(dl, function(x) coef(summary(x)) )
Doesn't create a grouping variable, so:
dfdl$group=rep(0:2, each=4)
David Winsemius, MD
West Hartford, CT
David Winsemius, MD
West Hartford, CT
______________________________________________
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.