Create List with Names but no Entries in R (Example)
This article illustrates how to construct a list with names but no entries in the R programming language.
Table of contents:
Let’s dig in…
Example: Create List with Empty Elements Using sapply() Function
This example shows how to use the sapply function to get a list with list names but without list entries.
As a first step, we have to create a vector of list names:
my_names <- LETTERS[1:5] # Create vector of names my_names # Print vector of names # [1] "A" "B" "C" "D" "E"
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
After executing the previous R syntax, we have created a list with names but without entries.
Video & Further Resources
Have a look at the following video on my YouTube channel. I’m explaining the R syntax of this tutorial in the video:
In addition, you might want to have a look at the related articles on my homepage. Some tutorials that are related to the construction of a list with names but without entries are listed below:
- Create Nested List in R
- Create Data Frame with Spaces in Column Names
- Create List of Vectors in R
- Extract Names of List Elements
- List All Column Names But One in R
- R Programming Examples
In this R tutorial you have learned how to create a list with names but without entries. Please let me know in the comments section below, if you have any further questions or comments.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






