# How to Create a List of Lists in R (With Example)

You can use the following basic syntax to create a list of lists in R:

```#define lists
list1 <- list(a=5, b=3)
list2 <- list(c='A', d='B')

#create list of lists
list_of_lists <- list(list1, list2)
```

The following example shows how to use this syntax in practice.

## Example: Create List of Lists in R

The following code shows how to create a list that contains 3 lists in R:

```#define lists
list1 <- list(a=5, b=3)
list2 <- list(c='A', d=c('B', 'C'))
list3 <- list(e=c(20, 5, 8, 16))

#create list of lists
list_of_lists <- list(list1, list2, list3)

#view the list of lists
list_of_lists

[]
[]\$a
 5

[]\$b
 3

[]
[]\$c
 "A"

[]\$d
 "B" "C"

[]
[]\$e
 20  5  8 16```

We can then use single brackets [ ] to access a specific list.

For example, we can use the following syntax to access the second list:

```#access second list
list_of_lists

[]
[]\$c
 "A"

[]\$d
 "B" "C"```

We can also use double brackets [[ ]] and the dollar sign operator \$ to access a specific element within a specific list.

For example, we can use the following syntax to access element d within the second list:

```#access element 'd' within second list
list_of_lists[]\$d

 "B" "C"
```

You can use similar syntax to access any element within any list.