Create List with Single Value in R (Example)
This page illustrates how to create a list containing only one value in R programming.
The article will contain one example for the construction of a list containing only one element. More precisely, the article looks as follows:
With that, let’s dive into it!
Example: Construct List with Single Value Using list() Function
The following R programming syntax demonstrates how to create a list with only one single list item.
For this task, we simply have to specify the value that we want to use within the list function.
Have a look at the following R code and its RStudio console output:
my_list <- list(10) # Create list my_list # Print list # [[1]] # [1] 10
We have created a list containing the single value 10.
Video & Further Resources
Do you need further info on the R code of this tutorial? Then you could watch the following video on my YouTube channel. I explain the contents of this post in the video.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Besides that, you could have a look at the related tutorials on my homepage. I have released several posts already:
- Add Key Value Pair to List
- Combine List of Vectors to Single Vector
- Create List of Installed Packages in R
- Create List of Vectors in R
- All R Programming Examples
This article has explained how to construct a list with a single element in the R programming language. If you have additional comments and/or questions, let me know in the comments.
Statistics Globe Newsletter