The most flexible of structures
[row, col] or by [el].[] subsets a list and returns a list.[[ ]] and $ return the object inside the list.$ allows subsetting by name.[1] 1 3
Negative indexing will drop that element (or set of elements) from the vector.
Discuss with a neighbor
Which of the following four objects are the same?
01:30
Discuss with a neighbor
Which of the following four objects are the same?
By atomic we mean:
List
A non-atomic vector that can contain atomic vectors of different types, as well as other lists. Created with list().
[][][] extracts elements of a vector (atomic or non-atomic) using a subsetting (atomic) vector.
[][] extracts elements of a vector (atomic or non-atomic) using a subsetting (atomic) vector.
$Ape
[1] 1 2 3
$Boy
[1] "a"
$Cat
[1] 4 5 6
But what if you want the actual data structure inside the list?
[[ ]][[ ]][[i]] extracts the original object inside the list.
To tell [] and [[ ]] apart, let’s use a metaphor of a train.
A list is like a train: an ordered line of cars, each holding cargo of whatever kind.
[]gives you back a train;[[ ]]gives you the cargo.


Draw the appropriate train or car for each of the following
x[1:2]x[[3]]x[-2]x[c(1, 1)]c(x[[3]], x[[1]])02:30
$$$ will extract a single element of a list by name.
[1] 4 5 6
Permits partial matching.
A list is a non-atomic vector that can contain:
Draw the train:
Draw the train, then write the R code to extract:
"rabbit""rabbit"y1:3202:00
[] subsets a list and returns a list.[[ ]] and $ return the object inside the list.$ matches by name, and permits partial matching.