You can do that using a recursive function.

rec.list <- function(len){
    if(length(len) == 1){
        vector("list", len)
    } else {
        lapply(1:len[1], function(...) rec.list(len[-1]))
    }
}

l <- rec.list(c(2, 3, 3, 4, 2, 3, 3))

Or perhaps with a 7-d list array? It might look bizarre at first, but it is a perfectly valid data structure.

l <- vector("list", 2*3*3*4*2*3*3)
dim(l) <- c(2, 3, 3, 4, 2, 3, 3)
l[[1,1,1,1,1,1,1]] <- "content"
Answer from Backlin on Stack Overflow
🌐
Statistics Globe
statisticsglobe.com › home › learn r programming (tutorial & examples) | free introduction › create nested list in r (2 examples)
Create Nested List in R (2 Examples) | Build List of Lists in for-Loop
March 21, 2022 - my_nested_list2 <- list() # Create empty list my_nested_list2 # Print empty list # list() Finally, we can run a for-loop over the vector of list names and concatenate another list to our main list using index positions and the get function:
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2025-01-13
How to Create an Empty List in R: A Comprehensive Guide with Examples – Steve’s Data Tips and Tricks
January 13, 2025 - Lists in R are versatile data structures that can hold elements of different types and sizes. Unlike vectors or matrices, which must contain elements of the same type, lists can store various data types including numbers, strings, vectors, and even other lists. ... # Create an empty list of length 5 fixed_length_list <- vector("list", 5) print(length(fixed_length_list))
Top answer
1 of 4
10

There's another way to assign to a list, using my_list[[name or number]] <-. If you really want to do that in a loop, just looping over things with names like iter1, iter2, ...

A <- list()
n_iter <- 2
for (i in 1:n_iter){
    iname <- paste("iter",i,sep="")
    A[[iname]] <- get(iname)
}

As @mnel pointed out, dynamically growing a list is inefficient. The alternative is, I think, to use lapply:

n_iter <- 2
inames <- paste("iter",1:n_iter,sep="")
names(inames) <- inames
A <- lapply(inames,get)

This can also be done with a data frame, which would be a better format if your sublists always have two elements, each having a consistent class (item1 being numeric and item 2 being character).

n_iter <- 2
DF <- data.frame(item1=rep(0,n_iter),item2=rep("",n_iter),stringsAsFactors=FALSE)
for (i in 1:n_iter){
     iname <- paste("iter",i,sep="")
     DF[i,] <- get(iname)
     rownames(DF)[i] <- iname
}

#       item1 item2
# iter1     1     a
# iter2     1     b

However, that's a pretty ugly way of doing things; things get messy pretty quickly when using get. With your data structure, maybe you want to create iter1 and iter2 in a loop and immediately embed them into the parent list or data frame?

n_iter = 10
DF <- data.frame(item1 = rep(0,n_iter), item2 = rep("",n_iter))
for (i in 1:n_iter){
    ... do stuff to make anum and achar ...
    DF[i,"item1"] <- anum
    DF[i,"item2"] <- achar
}

Where anum and achar are the values of item1 and item2 you want to store from that iteration. Elsewhere on SO, they say that there is an alternative using the data.table package that is almost 10x as fast/efficient as this sort of data-frame assignment.

Oh, one last idea: if you want to put them in a list first, you can easily convert to a data frame later with

DF <- do.call(rbind.data.frame,A)
2 of 4
5

This gets you the equivalent of your All

c(iter1=list(iter1), iter2=list(iter2))

> identical(c(iter1=list(iter1), iter2=list(iter2)), All)
[1] TRUE

Let's say you'd like to add a third list to All:

c(All, list(iter3=iter3))

If you don't care for the list names, it looks a little cleaner

 c(list(iter1), list(iter2))
🌐
GeeksforGeeks
geeksforgeeks.org › r language › convert-dataframe-to-nested-list-in-r
Convert dataframe to nested list in R - GeeksforGeeks
July 23, 2025 - # Creation of sample data frame df<-data.frame( age=c(1,2,3,4,5), name=c('a','b','c','d','e') ) nested_list<-list() for(i in df){ nested_list<-append(nested_list,list(i)) } # Print data frame print('Data Frame') print(df) # Check the type of variable nested_list print('Type:-') print(typeof(nested_list)) # Print created nested list print('Nested List') print(nested_list) ... As in R Programming, there are no in-built functions to convert data frame to list, following are the steps to convert · At first we created a sample data frame(df) and an empty list(nested_list)
🌐
R-bloggers
r-bloggers.com › r bloggers › the ultimate guide to creating lists in r: from basics to advanced examples
The Ultimate Guide to Creating Lists in R: From Basics to Advanced Examples | R-bloggers
October 29, 2024 - Here’s the basic syntax: # Basic list creation my_list <- list(1, "hello", c(2,3,4)) You can create an empty list and add elements later: # Create empty list empty_list <- list() # Create a list with different types of elements student_info ...
🌐
Statistics Globe
statisticsglobe.com › home › learn r programming (tutorial & examples) | free introduction › create list with names but no entries in r (example)
Create List with Names but no Entries in R (Example) | Empty Elements
June 7, 2022 - As you can see in the RStudio console, we have created a vector of five elements. We’ll use this vector to define our list names in the next step: my_list <- sapply(my_names, function(x) NULL) # Create list with empty elements my_list # Print list with empty elements # $A # NULL # # $B # NULL # # $C # NULL # # $D # NULL # # $E # NULL
Find elsewhere
🌐
Steve's Data Tips and Tricks
spsanderson.com › steveondata › posts › 2024-10-29
The Ultimate Guide to Creating Lists in R: From Basics to Advanced Examples – Steve’s Data Tips and Tricks
October 29, 2024 - The primary way to create a list in R is using the list() function. Here’s the basic syntax: # Basic list creation my_list <- list(1, "hello", c(2,3,4)) You can create an empty list and add elements later:
🌐
Nabble
r.789695.n4.nabble.com › Creating-a-list-of-empty-lists-td840277.html
R help - Creating a list of empty lists
R › R help · Creating a list of empty lists · ‹ Previous Topic Next Topic › · Locked 5 messages · Magnus Thor Torfason · Reply | Threaded · Open this post in threaded view · Romain Francois
🌐
TutorialsPoint
tutorialspoint.com › how-to-create-data-frame-using-nested-list-elements-in-r
How to create data frame using nested list elements in R?
June 3, 2021 - For example, if we have a nested called LIST then the data frame can be created by using the command − · data.frame(matrix(unlist(LIST),ncol=”No of columns we want”,byrow=F)) Check out the below example to understand how it works. ... nestedList<-list(list(x1=rpois(20,2),x2=rpois(20,2)),list(y1=rpois(20,2),y2=rpois(20,2))) nestedList
🌐
Learn By Example
learnbyexample.org › r-list
R List - Learn By Example
April 20, 2020 - Learn to create a list in R, subset (by name and position), modify, access add insert remove elements, create nested list, combine lists and flatten a list
🌐
RCODER
r-coder.com › home › r introduction › list in r
LIST in R language ⚡ [CREATE, COMPARE, JOIN, EXTRACT, ... ]
January 2, 2024 - # Empty list empty_list <- list() # Creating an empty list with 3 elements empty_list <- vector("list", length = 3)
🌐
Statology
statology.org › home › how to create an empty list in r (with examples)
How to Create an Empty List in R (With Examples)
July 26, 2021 - This tutorial explains how to create an empty list in R, including several examples.
🌐
How to Create
howtocreate.com › home › how to create an empty list in r
How to create an empty list in r
May 16, 2021 - You can create an empty list using an empty pair of square brackets [] or the type constructor list() , a built-in function that creates an empty list when no arguments are passed. Square brackets [] are commonly used in Python to create empty lists because it is faster and more concise.
🌐
Vitessce
r-docs.vitessce.io › reference › obj_list.html
Create an empty named list — obj_list • vitessceR
A helper function to construct an empty list which converts to a JSON object rather than a JSON array.
🌐
GeeksforGeeks
geeksforgeeks.org › r language › how-to-create-empty-list-in-r
How to Create Empty List in R? - GeeksforGeeks
December 3, 2021 - # create empty list with length 3 data = vector(mode='list', length=3) print(data) # display length print(length(data)) ... Decision Making in R Programming - if, if-else, if-else-if ladder, nested if-else, and switch3 min read
🌐
UC Business Analytics
uc-r.github.io › lists
Managing Lists · UC Business Analytics R Programming Guide
A list is an R structure that allows ... section I will guide you throught the basics of managing lists to include: ... To create a list we can use the list() function....
🌐
Quora
quora.com › How-do-you-create-an-empty-nested-list-in-Python
How to create an empty nested list in Python - Quora
Answer: Being strictly pedantic there is no such thing! There is only one empty list in Python: this is []. Note the nested construct [[]] is not an empty list. This list has one element. It is easy to build up a nested list like this: empty_nested_list = [[[],[],[]], [[],[]], [[]], []] Thi...