Syntax of sapply and lapply in r

廉价感情. 提交于 2019-12-24 01:27:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!