[R] "Inverting" a list

Gabor Grothendieck ggrothendieck at gmail.com
Thu Feb 7 00:00:40 CET 2008


This isn't a single command but its pretty short:

unstack(stack(L)[2:1])

On Feb 6, 2008 5:51 PM, hadley wickham <h.wickham at gmail.com> 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(
>  "1" = c("a", "b"),
>  "2" = c("a", "d"),
>  "3" = "a",
>  "4" = "2"
> )
>
> Hadley
>
> --
> http://had.co.nz/
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list