Reputation: 1610
Several of the answers to this question suggest that the best way to extract a subset from a list is to use something like sapply(mylist, "[", y)
. I found this rather disturbing, because I have never seen anything to suggest that we can use "[" as if it's a function. Where is this documented? I checked ?'[['
for my version, 3.6.3, but I can't see any reference to this functionality in that documentation.
Upvotes: 2
Views: 67
Reputation: 132576
All operators in R are functions. This is documented in the language definition:
https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Operators
Like the other operators, indexing is really done by functions, and one could have used
`[`(x, 2)
instead ofx[2]
.
Upvotes: 3