Here is one way:

xst <- stack(x)
let <- letters[cumsum(duplicated(match(xst$ind, letters))) + match(xst$ind,
letters)]
with(xst,
     structure(split(structure(values, names = let), ind), .Names =
row.names(xst)[1:length(unique(ind))]))



On Tue, Aug 10, 2010 at 1:58 PM, Carlos Petti <carlos.pe...@gmail.com>wrote:

> Dear list,
>
> I have a list, as follows :
>
> a <- 5
> names(a) <- "a"
> b <- 9
> names(b) <- "b"
> c <- 15
> names(c) <- "c"
> x <- list("i" = a, "j" = b, "j" = c)
>
> I want to invert the list, like this :
>
> $a
> i
> 5
>
> $b
> j  k
> 9 15
>
> I do not find a clean solution.
>
> Could anyone give me elegant ideas ?
>
> Thanks in advance,
> Carlos
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
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