Two Noobie questions
Allen, I would suggest reading about the str() function. It's great for getting "inside" model outputs and seeing how they are constructed so you can extract all the specific calculations you want. Its a bit fiddly to get used to but there are plenty of examples on this forum. Hope this helps. Simon. ----- Original Message ----- From: "AllenL" <allen.larocque at gmail.com> To: <r-help at r-project.org> Sent: Tuesday, January 06, 2009 7:47 PM Subject: Re: [R] Two Noobie questions
Thanks for your help!
I combined the above two to get the following, which seems to work (if
somewhat inelegant):
int.List<-unlist(lapply(lmList, function(x) {coef(x)[1]}),use.names=FALSE)
lmList is my list of lm objects.
-Allen
David Winsemius wrote:
On Jan 6, 2009, at 1:50 PM, AllenL wrote:
1. I have a list of lm (linear model) objects. Is it possible to select, through subscripts, a particular element (say, the intercept) from all the models? I've tried something like this:
?coef if your list of models is ml, then perhaps something like this partially tested idea: lapply(ml, function(x) coef(x)[1] ) This is what I get using that formulation an available logistic model:
> coef(lr.TC_HDL_BMI)[1]
Intercept -6.132448
List[[1:length(list)]][1] All members of the list are similar. My goal is to have a list of the intercepts and lists of other estimated parameters. Is it better to convert to a matrix? How to do this? 2. Connected to this, how do I convert from a list back to a vector? This problem arose from using "split" to split a vector by a factor, then selecting a subset of this (ie. length>10), leaving me with subset list of my original. Unsplit(newList, factor) doesn't work, presumably due to my removal of some values. Thoughts?
?unlist
> ll <- list(1,2,3,4) > ll
[[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 4
> unlist(ll)
[1] 1 2 3 4
> str(unlist(ll))
num [1:4] 1 2 3 4
> is.vector(unlist(ll))
[1] TRUE -- David Winsemius
Thanks! -Allen -- View this message in context: http://www.nabble.com/Two-Noobie-questions-tp21316554p21316554.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.
______________________________________________ R-help at 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.
-- View this message in context: http://www.nabble.com/Two-Noobie-questions-tp21316554p21317630.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at 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.