To initialize a list in R, you can use the list()
function to create an empty list or provide elements inside the list()
function to create a list with initial values.
In this example,
list()
function to create an empty list and assign it to the variable empty_list
.empty_list <- list()
print("Empty List:")
print(empty_list)
[1] list()
In this example,
list()
function and provide elements inside the function to create a list with initial values.fruits
.fruits <- list("Apple", "Banana", "Cherry")
print("List with Elements:")
print(fruits)
[[1]] [1] "Apple" [[2]] [1] "Banana" [[3]] [1] "Cherry"
In this tutorial, we learned How to Initialize a List in R language with well detailed examples.