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(
This isn't a single command but its pretty short:
unstack(stack(L)[2:1])
On Feb 6, 2008 5:51 PM, hadley wickham <[EMAIL PROTECTED]> wrote:
> Is there a built in function to invert a list? i.e. to go from
>
> list(
> a = c("1", "2", "3"),
> b = c("1"),
> d = c("2", "4")
> )
>
> to
>
> list(
>
Is there a built in function to invert a list? i.e. to go from
list(
a = c("1", "2", "3"),
b = c("1"),
d = c("2", "4")
)
to
list(
"1" = c("a", "b"),
"2" = c("a", "d"),
"3" = "a",
"4" = "2"
)
Hadley
--
http://had.co.nz/
__
R-help@r-projec
3 matches
Mail list logo