In R, you can create a list of lists using the `list()` function and specifying lists as elements of the outer list.
In this example,
list1
and list2
.list_of_lists
using the list()
function and initialize it with the inner lists.list1 <- c(1, 2, 3)
list2 <- c('a', 'b', 'c')
list_of_lists <- list(list1, list2)
print(list_of_lists)
[[1, 2, 3], ['a', 'b', 'c']]
In this example,
list_of_lists_empty
.list3
and list4
.list()
function to add the inner lists list3
and list4
to the outer list list_of_lists_empty
.list_of_lists_empty <- list()
list3 <- list()
list4 <- list()
list_of_lists_empty <- list(list3, list4)
print(list_of_lists_empty)
[[], []]
In this tutorial, we learned How to create a List of Lists in R language with well detailed examples.