Lots of ways to do this ... here?s one method which performs this action ...
> # Line 1 - Set up the order for the output data frame ...
> outOrder <- c("Intercept", "BAE", "TS", "BMI", "PIB", "RDQ.L.2")
> # Line 2 - Call the rbind function selecting outputs from the list in
correct order
> do.call("rbind", lapply(myList, "[", outOrder))
Intercept BAE TS BMI PIB RDQ.L.2
[1,] 3.2349520 NA -0.03115679 -0.05632398 0.1436319 -0.8185403
[2,] 0.5690662 NA NA NA 0.1674238 -0.9336926
[3,] 1.5804260 NA NA NA NA -1.0935110
[4,] 0.8709023 NA NA NA 0.1222120 -1.2918590
[5,] 0.7874391 NA NA NA 0.1582175 -1.4346400
[6,] 3.5260160 -0.2153779 NA NA NA -1.3276920
Lots of other ways include:-
* Use sapply in the above call and change output matrix into a data frame
* Look through elements of list and append to a data frame
Hope that helps ...
Rich.
S-PLUS & R Training & Consulting
mangosolutions
Tel +44 1249 467 467
Fax +44 1249 467 468
________________________________________
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Heymans, MW
Sent: 18 April 2006 06:35
To: s-news@lists.biostat.wustl.edu
Subject: [S] list to data.frame
Dear s-list,
I have the following list as output, with different variable names and
values within each list component:
[[1]]:
Intercept TS BMI PIB RDQ.L.2
3.234952 -0.03115679 -0.05632398 0.1436319 -0.8185403
[[2]]:
Intercept PIB RDQ.L.2
0.5690662 0.1674238 -0.9336926
[[3]]:
Intercept RDQ.L.2
1.580426 -1.093511
[[4]]:
Intercept PIB RDQ.L.2
0.8709023 0.122212 -1.291859
[[5]]:
Intercept PIB RDQ.L.2
0.7874391 0.1582175 -1.43464
[[6]]:
Intercept BAE RDQ.L.2
3.526016 -0.2153779 -1.327692
Help is appreciated how to transfer this list into a data.frame / matrix
with variable names on top of the data.frame / matrix. The order of the
variable names has to be:
[1] "Intercept" "BAE" "TS" "BMI" "PIB" "RDQ.L.2"
Thanks!
Martijn
VUmc, Amsterdam
|