[R] "Inverting" a list

Richard M. Heiberger rmh at temple.edu
Thu Feb 7 00:19:57 CET 2008


A more primitive method is about 5 times faster than Gabor's.

L <- list(
            a = c("1", "2", "3"),
            b = c("1"),
            d = c("2", "4")
)

system.time(
for (i in 1:100)
{t1 <- unlist(L)
names(t1) <- rep(names(L), lapply(L, length))
tapply(names(t1), t1, c)
}
)

system.time(
for (i in 1:100)
unstack(stack(L)[2:1])
)



More information about the R-help mailing list