问题
I have been looking into ways to separate a list in r based on the index of the sub values and I have seen this piece of code pop up a lot:
sapply(myList, "[", 2)
I was wondering if anyone would be able to explain this to me as the only syntax that I have used for sapply before is:
sapply(myList, Function)
回答1:
"["
is by itself a function.
when you call sapply(LIST, "[", 2)
it means extract the second element of each sub-list.
The 2
which you passed goes as an argument to the function [
making it [2]
来源:https://stackoverflow.com/questions/41761499/syntax-of-sapply-and-lapply-in-r