Chapter 7 Lists

Lists arrange elements in a collection of vectors or other data structures. In other words, lists are just a collection of variables, that have no constraints on what types of variables can be included.

Emma <- list(age = 26,
             siblings = TRUE,
             parents = c("Mike", "Donna")
             )

Here, R has created a list variable called Emma, which contains three different variables - age, siblings, and parents. Lets have a look at how R stores this list:

print(Emma)
## $age
## [1] 26
## 
## $siblings
## [1] TRUE
## 
## $parents
## [1] "Mike"  "Donna"

If you wanted to extract one element of the list, you would use the $ operator:

Emma$age
## [1] 26

You can also add new entries to the list, again using the $. For example:

Emma$handedness <- "right"
print(Emma)
## $age
## [1] 26
## 
## $siblings
## [1] TRUE
## 
## $parents
## [1] "Mike"  "Donna"
## 
## $handedness
## [1] "right"