Dear useRs, If i have a list of the following form and i want to convert the coefficient section of each element, combined into one matrix of dimension 3*5. How can i do that?I hope i am clear thank in advance [[1]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: x0 x xx y yy 1.0000 -0.4250 0.2494 0.1683 -0.7449 [[2]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: x0 x xx y yy 1.0000 -0.6355 0.5876 0.2518 -0.7293 [[3]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: x0 x xx y yy 1.0000 0.5778 0.3838 0.4207 -0.1354 [[alternative HTML version deleted]]
Hi, Try: set.seed(48) lst1<-replicate(3,data.frame(y=rnorm(50),z=runif(50),x=sample(10:15,50,replace=TRUE)),simplify=FALSE) ?t(sapply(lst1,function(u) coef(lm(y~0+x+z,data=u))))? #change accordingly #?????????????? x????????? z #[1,] -0.01020553? 0.3852990 #[2,] -0.01157726? 0.3986898 #[3,]? 0.01788307 -0.5624307 A.K. ----- Original Message ----- From: eliza botto <eliza_botto at hotmail.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Wednesday, September 11, 2013 10:22 AM Subject: [R] list to matrix Dear useRs, If i have a list of the following form and i want to convert the coefficient section of each element, combined into one matrix of dimension 3*5. How can i do that?I hope i am clear thank in advance [[1]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: ? ? x0? ? ? ? x? ? ? xx? ? ? ? y? ? ? yy? 1.0000? -0.4250? 0.2494? 0.1683? -0.7449? [[2]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: ? ? x0? ? ? ? x? ? ? xx? ? ? ? y? ? ? yy? 1.0000? -0.6355? 0.5876? 0.2518? -0.7293? [[3]] Call: lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) Coefficients: ? ? x0? ? ? ? x? ? ? xx? ? ? ? y? ? ? yy? 1.0000? 0.5778? 0.3838? 0.4207? -0.1354? ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ 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.
Hi Do not post HTML. Why you did not populate your list directly with coefficients by let say coef(lm.result)? Anyway, you can reveal structure of individulal list component by str(your.object[[1]]). After that you can extract coefficient component and use sapply/lapply probably with rbind. maybe sapply(lapply(your.list, coef), rbind) can do it. Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of eliza botto > Sent: Wednesday, September 11, 2013 4:23 PM > To: r-help at r-project.org > Subject: [R] list to matrix > > Dear useRs, > If i have a list of the following form and i want to convert the > coefficient section of each element, combined into one matrix of > dimension 3*5. How can i do that?I hope i am clear thank in advance > > [[1]] > Call: > lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) > Coefficients: > x0 x xx y yy > 1.0000 -0.4250 0.2494 0.1683 -0.7449 > > [[2]] > Call: > lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) > Coefficients: > x0 x xx y yy > 1.0000 -0.6355 0.5876 0.2518 -0.7293 > > [[3]] > Call: > lm(formula = mm[, i] ~ 0 + (x0 + x + xx + y + yy)) > Coefficients: > x0 x xx y yy > 1.0000 0.5778 0.3838 0.4207 -0.1354 > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.