2
x <- list(a=list(1, 2, 3), b=list(4, 5, 6), c=list(7, 8, 9))

then class(x[1]) and class(x[[1]]) both show :

[1] "list"

then x[[1]][[3]] output:

[1] 3

however, x[1][[3]] output:

Error in x[1][[3]] : subscript out of bounds

So, why x[1][[3]] doesn't work? in my opinion, you can use [[ to subset the element of a list.

FT. Ye
  • 33
  • 3
  • 1
    See [this post](https://stackoverflow.com/questions/36777567/is-there-a-logical-way-to-think-about-list-indexing/36815401#36815401) and the links for some commentary. `x[[1]][[3]]` or `x[[c(1, 3)]]` reference the third element of the first list element. `x[1]` returns a list element of length 1, so the second `[[3]]` has no third element to extract. – lmo Sep 05 '17 at 19:58
  • thank you. yes, x[1] is still a list of list and with length of 1. – FT. Ye Sep 06 '17 at 13:41

0 Answers0