(l1 <- list(1, 2, 3))[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
(l2 <- list("bob", TRUE, 33, 42+3i))[[1]]
[1] "bob"
[[2]]
[1] TRUE
[[3]]
[1] 33
[[4]]
[1] 42+3i
(l3 <- list(c(1, 2), c(3, 4)))[[1]]
[1] 1 2
[[2]]
[1] 3 4
We construct lists using the list() function. Lists place essentially no restrictions on the nature of their contents:
We can name the elements of a list by defining the list slots via key-value pairs.
$name
[1] "bob"
$alive
[1] TRUE
$age
[1] 33
$relationshipStatus
[1] 42+3i
We can use the names() function to access and modify the names of a list’s slots.
[1] "name" "alive" "age"
[4] "relationshipStatus"
$first
[1] 1
$second
[1] 2
$third
[1] 3
Create a list to describe yourself. Include the following named elements in your list: