'[[' and recursiveness

  • '[[' operates recursively when given mulitple indexes.
  • Compare:
# atomic vector with '['
x <- 1:10
x[c(1, 2)]
## [1] 1 2
y <- list(a = 1:10,
          b = 11:20)

# list with '[['
y[[c(1,2)]]   # equivalent to y[[1]][[2]]
## [1] 2