Open In App

How to Create Empty List in R?

Last Updated : 03 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to create an empty list in R Programming Language.

Create Empty List in R with Length of Zero

Here we are going to create an empty list with length 0 by using list() function.

Syntax:

data=list()

Example:

R




# create empty list
data = list()
 
print(data)
 
# display length
print(length(data))


Output:

list()
[1] 0

Create Empty List in R with Specific Length

Here we are specifying length in an empty list using the following syntax.

vector(mode='list', length)

where,

  • mode specifies the list
  • length specifies the length of empty list

Example:

R




# create empty list with length 3
data = vector(mode='list', length=3)
 
print(data)
 
# display length
print(length(data))


Output:

[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[1] 3

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads