You can easily make lists of lists

list1 <- list(a = 2, b = 3)
list2 <- list(c = "a", d = "b")
mylist <- list(list1, list2)

mylist is now a list that contains two lists. To access list1 you can use mylist[[1]]. If you want to be able to something like mylist$list1 then you need to do somethingl like

mylist <- list(list1 = list1, list2 = list2)
# Now you can do the following
mylist$list1

Edit: To reply to your edit. Just use double bracket indexing

a <- list_all[[1]]
a[[1]]
#[1] 1
a[[2]]
#[1] 2
Answer from Dason on Stack Overflow
Top answer
1 of 2
2

A short version:

 sapply(GroupedList, nrow)
2 of 2
0

I would suggest this approach. You can use lapply() as you have a list and the bind the results with do.call() and rbind():

#Data
List <- list(structure(list(preds = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), ground_truth = c(1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 
1L, 0L, 1L)), class = "data.frame", row.names = c("21528", "14033", 
"3770", "16734", "20867", "26342", "687", "7501", "15543", "13239", 
"3403")), structure(list(preds = c(1L, 1L, 1L, 1L, 1L, 1L), ground_truth = c(1L, 
1L, 0L, 1L, 1L, 1L)), class = "data.frame", row.names = c("5278", 
"4745", "12622", "26877", "441", "20626")), structure(list(preds = c(1L, 
1L), ground_truth = c(1L, 1L)), class = "data.frame", row.names = c("7431", 
"16675")), structure(list(preds = integer(0), ground_truth = integer(0)), row.names = character(0), class = "data.frame"))

The code:

#Obtain dim
O <-as.data.frame(do.call(rbind,lapply(List,function(x) dim(x)[1])))
#Format
O$List <- rownames(O)
O <- O[,c(2,1)]
names(O)[2]<-'count'
rownames(O)<-NULL

Output:

  List count
1    1    11
2    2     6
3    3     2
4    4     0

Update: Here another approach using for()

#Data
List2 <- list(l1 = list(structure(list(preds = c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L), ground_truth = c(1L, 0L, 1L, 1L, 0L, 1L, 
1L, 1L, 1L, 0L, 1L)), class = "data.frame", row.names = c("21528", 
"14033", "3770", "16734", "20867", "26342", "687", "7501", "15543", 
"13239", "3403"))), l2 = list(structure(list(preds = c(1L, 1L, 
1L, 1L, 1L, 1L), ground_truth = c(1L, 1L, 0L, 1L, 1L, 1L)), class = "data.frame", row.names = c("5278", 
"4745", "12622", "26877", "441", "20626"))), l3 = list(structure(list(
    preds = c(1L, 1L), ground_truth = c(1L, 1L)), class = "data.frame", row.names = c("7431", 
"16675"))), l4 = list(structure(list(preds = integer(0), ground_truth = integer(0)), row.names = character(0), class = "data.frame")))

The code:

#Create empty list to save results
elist <- list()
#Loop
for(i in 1:length(List2))
{
  #Check dim
  if(dim(List2[[i]][[1]])[1]>0)
  {
    df <- data.frame(name=names(List2[i]),count=dim(List2[[i]][[1]])[1])
    elist[[i]] <- df
  }
}
#Now bind
O <- do.call(rbind,elist)

Output:

  name count
1   l1    11
2   l2     6
3   l3     2
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 58625570 โ€บ naming-list-of-lists-and-list-of-lists-of-lists-in-r
naming list of lists and list of lists of lists in r - Stack Overflow
Thanks, I will look into the [ function. I would like to rename them based on some vector and avoid writing out multiple times names(mylist$a1) <- "newa1" ... the input would be something like mynames <- c("newa1", "newa2") then I would like to name the second level of the list as these new names.
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 36311708 โ€บ make-dataframe-from-a-list-of-lists-in-r
Make dataframe from a list of lists in R - Stack Overflow
We'll walk the higher level of the list by position, and the inner level by name since the names are consistent across sub-lists at the inner level. Note here that the key idea is essentially to reverse what would be the intuitive way of indexing; since I want to pull observations at the second level from across observations at the first level, the inner call to sapply traverses multiple values of level one for each value of the name at level two.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 37076783 โ€บ output-list-of-list-in-r
Output list of list in R - Stack Overflow
June 24, 2016 - object.1 = replicate(1000,Monte.Carlo(30,0.5,1.4,0.8,X1)) Then I made a dummy dataframe (which is a list of lists) with the column names being the statistics you specified