简体   繁体   中英

How to visualize a list of lists of lists of … in R?

I have a very deep list of lists in R. Now I want to print this list to the standard output to get a better overview of the elements. It should look like the way the StatET plugin for eclipse shows a list.
Example list:

l6 = list()
l6[["h"]] = "one entry"
l6[["g"]] = "nice"
l5 = list()
l5[["e"]] = l6
l4 = list()
l4[["f"]] = "test"
l4[["d"]] = l5
l3 = list()
l3[["c"]] = l4
l2 = list()
l2[["b"]] = l3
l1 = list()
l1[["a"]] = l2

This should print like:

List of 1
 $ a:List of 1
  ..$ b:List of 1
  .. ..$ c:List of 2
  .. .. ..$ f: chr "test"
  .. .. ..$ d:List of 1
  .. .. .. ..$ e:List of 2
  .. .. .. .. ..$ h: chr "one entry"
  .. .. .. .. ..$ g: chr "nice"

I know this is possible with recursion and the deepness.
But is there a way to do this with the help of rapply or something like that?

Thanx in advance,
Martin

我想你可以通过给予你想要的东西

str(l1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM