[R] coef(summary) and plyr
moleps
moleps2 at gmail.com
Tue Aug 10 00:39:42 CEST 2010
Upon reading the plyr documentation that was the distinct impression I got and I´m glad that "whatever expectations I had developed regarding plyr" were fulfilled. Thx for the input Hadley.
Maybe this is a cumbersome solution, but it works..
And Matthew, I will most definitively look into the datatable library.
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
test<-function(a){
coef(summary(a))->lo
a<-colnames(lo)
b<-rownames(lo)
c<-length(a)
e<-character(0)
r<-NULL
for (x in (1:c)){
d<-rep(paste(a[1:c],b[x],sep=" "))
e<-paste(c(e,d))
t<-lo[x,]
r<-c(r,t)
names(r)<-e
}
return(r)
}
ldply(dl,function(x) test(x))->g
g
Regards,
Moleps
On 9. aug. 2010, at 19.55, Hadley Wickham wrote:
>>> That's exactly what dlply does - so you should never have to do that
>>> yourself.
>>
>> I'm unclear what you are saying. Are you saying that the plyr function
>> _should_ have examined the objects in that list and determined that there
>> were 4 rows and properly labeled the rows to indicate which list they came
>> from?
>
> Yes, exactly. It's the output from coef(summary(x)) that makes it
> look like this isn't happening.
>
> Hadley
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
More information about the R-help
mailing list