[R] list to matrix?

R. Michael Weylandt michael.weylandt at gmail.com
Tue Dec 4 21:15:10 CET 2012


On Tue, Dec 4, 2012 at 8:09 PM, Sam Steingold <sds at gnu.org> wrote:
> How do I convert a list to a matrix?
>
> --8<---------------cut here---------------start------------->8---
> list(c(50000, 101), c(1e+05, 46), c(150000, 31), c(2e+05, 17),
>     c(250000, 19), c(3e+05, 11), c(350000, 12), c(4e+05, 25),
>     c(450000, 19), c(5e+05, 16))

do.call(rbind, LIST)

or

do.call(cbind, LIST)

depending on your desired direction. The do.call syntax takes a
function name and uses a list as arguments to that function, returning
the result. Super useful for these situations where you collect things
and something like

cbind(x[[1]],x[[2]], x[[3]]...)

isn't feasible or possible.

MW




More information about the R-help mailing list