Open In App

How to Create Empty List in R?

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:






# 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,

Example:




# 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
Article Tags :