Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to view a list

Tags:

list

r

When I have data.frame objects, I can simply do View(df), and then I get to see the data.frame in a nice table (even if I can't see all of the rows, I still have an idea of what variables my data contains).

But when I have a list object, the same command does not work. And when the list is large, I have no idea what the list looks like.

I've tried head(mylist) but my console simply cannot display all of the information at once. What's an efficient way to look at a large list in R?

like image 633
Adrian Avatar asked Sep 16 '15 20:09

Adrian


2 Answers

Here's a few ways to look at a list:

Look at one element of a list:

myList[[1]]

Look at the head of one element of a list:

head(myList[[1]])

See the elements that are in a list neatly:

summary(myList)

See the structure of a list (more in depth):

str(myList)

Alternatively, as suggested above you could make a custom print method as such:

printList <- function(list) {

  for (item in 1:length(list)) {

    print(head(list[[item]]))

  }
}

The above will print out the head of each item in the list.

like image 72
giraffehere Avatar answered Sep 22 '22 22:09

giraffehere


I use str to see the structure of any object, especially complex list's

Rstudio shows you the structure by clicking at the blue arrow in the data-window:

enter image description here

like image 26
Rentrop Avatar answered Sep 21 '22 22:09

Rentrop