R: Why is the [[ ]] approach for subsetting a list faster than using $?

二次信任 提交于 2019-11-28 18:10:06

Function [[ first goes through all elements trying for exact match, then tries to do partial match. The $ function tries both exact and partial match on each element in turn. If you execute:

system.time (
    for (i in 1:10000) {
     a.long.list[["something9973", exact=FALSE]]
     }
)

i.e., you are running a partial match where there is no exact match, you will find that $ is in fact ever so slightly faster.

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