I work more and more with highly nested lists such as:
mynestedlist<-list(list(LETTERS,month.name),list(list(seq(1,100,5),1,1),seq(1,100,5),seq(1,100,5)))
and sometimes I struggle to understand the structure of the list I am working on. I was wondering if there is any way to display the hierarchical structure of a list, using dendrogram-like graphs maybe.
I know I can use str
to print the structure of a list:
str(mynestedlist,max.level=1)
However, a graphical way to display lists would be more useful!
Two-dimensional list can be created in R programming by creating more lists in a list or simply, we can say nested lists. The list() function in R programming is used to create a list. In this article, we'll learn to create plot graph using Two Dimensional List in R programming.
How to Create Lists in R? We can use the list() function to create a list. Another way to create a list is to use the c() function. The c() function coerces elements into the same type, so, if there is a list amongst the elements, then all elements are turned into components of a list.
Data Visualization using R Programming Lists are the R objects which contain elements of different types like − numbers, strings, vectors and another list inside it. A list can also contain a matrix or a function as its elements. List is created using list() function.
You may check the data.tree
package. It allows to print nested list pretty nicely and it doesn't need you to write complicated function. Here is an example:
library(data.tree)
> dt <- FromListSimple(mynestedlist)
> dt
levelName
1 Root
2 ¦--1
3 °--2
4 °--1
This allows you to check at the level of list, and you can combine this with str
to get a full picture of your list structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With