本文介绍了r 中 sapply 和 lapply 的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在寻找根据子值的索引在 r 中分隔列表的方法,我看到这段代码弹出了很多:
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)
我想知道是否有人能够向我解释这一点,因为我之前用于 sapply 的唯一语法是:
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)
推荐答案
"["
本身就是一个函数.
当您调用 sapply(LIST, "[", 2)
时,表示提取每个子列表的第二个元素.
when you call sapply(LIST, "[", 2)
it means extract the second element of each sub-list.
您传递的 2
作为函数 [
的参数,使其成为 [2]
The 2
which you passed goes as an argument to the function [
making it [2]
这篇关于r 中 sapply 和 lapply 的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!