On Aug 9, 2010, at 10:11 AM, moleps wrote:
ldply doesnt need a grouping variable as far as I understand the
command..
There is one further improvement to consider. When I tried using dlply
to tackle a problem on which I had been bashing my head for the last
three days and it gave just the results I had been looking for, I also
noticed that the dlply function returns the grouping variable levels
in an attribute, "split_labels", which could be unlisted to use as an
argument to the rep() call I suggested earlier:
dfdl$group=rep(unlist(attr(dl, "split_labels")), each=4)
That might make the results more self-documenting in situations where
the grouping levels were more involved than 0:2.
(Now, if I can get rms::Predict to behave as nicely with the plyr
functions as did rms::cph, I will be home free.)
--
David.
"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.