什么文档告诉我们“[”可以用作函数?
What documentation tells us that "[" can be used as a function?
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的几个答案。
R 中的所有运算符都是函数。这记录在语言定义中:
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 of x[2]
.
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的几个答案。
R 中的所有运算符都是函数。这记录在语言定义中:
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]
.