[R] Efficient access to elements of a list of lists

Benilton Carvalho beniltoncarvalho at gmail.com
Sun Mar 11 17:18:53 CET 2012


I have a long list of lists from which I want to efficiently extract
and rbind elements. So I'm using the approach below:

f <- function(i){
    out <- replicate(5, list(matrix(rnorm(80), nc=20)))
    names(out) <- letters[1:5]
lst <- lapply(1:1.5e6, f)
(t0 <- system.time(tmp <- do.call(rbind, lapply(lst, '[[', 'b'))))

Is there anything better/faster than the do.call+rbind+lapply combo
above? On this example, the combo takes roughly 20s on my machine...
but on the data I'm working with, it takes more than 1 minute... And
given that I need to repeat the task several times, the cumul. amount
of time is significant for me.

Thank you for any suggestion/comment,


More information about the R-help mailing list