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@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.

Reply via email to