[R] list to matrix
arun
smartpink111 at yahoo.com
Wed Sep 11 17:15:08 CEST 2013
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.
More information about the R-help
mailing list