[R] Matrix from List

From: Nelson Villoria <nvilloria_at_gmail.com>
Date: Fri, 25 Jul 2008 17:32:23 -0400


Hello, I have a list in which each element is a list. I want to create a matrix indexed by the two indices of the list. I have been using do.call, but I am not getting what I want. Let me show you:

> l.intercepts #the list that nests another list
$`1995`
$`1995`$`31`
(Intercept)

   25.37164

$`1995`$`33`
(Intercept)

   26.66755

$`2006`
$`2006`$`31`
(Intercept)

   25.86621

$`2006`$`33`
(Intercept)

   26.44245

I want a matrix like

1995 31 25.37164
1995 33	26.66755
2006 31 25.86621
2006 33 26.44245

I notice that if I do:

> l.intercepts_1 <- lapply(l.intercepts, function(x) do.call(rbind, x))

I get:

> l.intercepts_1

$`1995`

    (Intercept)

31     25.37164
33     26.66755

$`2006`

    (Intercept)

31     25.86621
33     26.44245

However,If I further write:
> do.call("rbind", l.intercepts_1)
I get:

    (Intercept)

31     25.37164
33     26.66755
31     25.86621
33     26.44245

Why do.call did not index by year (i.e. 1995 and 2006) as it did before for 31 and 33? Any suggestion about how to accomplish this task? Help is greatly appreciated.

Nelson Villoria



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. Received on Fri 25 Jul 2008 - 21:35:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Jul 2008 - 03:32:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive