[R] how to flatten a list to the same level?

Mark Heckmann mark.heckmann at gmx.de
Fri Jan 8 16:35:27 CET 2010


I have a nested list l like:

l <- list(A=c(1,2,3), B=c("a", "b"))
l <- list(l,l, list(l,l))

I want the list to be unlisted, but not on the lowest level of each  
"branch".
I want the lowest level of each list branch to remain as it is.
So unlist or unlist(rec=F) do not work here as the level of nesting  
may differ on the elements.
The result should look like:

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

$A
[1] 1 2 3

$B
[1] "a" "b"

Any ideas?
TIA!

Mark


–––––––––––––––––––––––––––––––––––––––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com



More information about the R-help mailing list