Why doesn't R allow $ operator on atomic vectors?

前端 未结 2 2018
陌清茗
陌清茗 2020-12-19 09:06

The following will throw the error \"Error in v$a : $ operator is invalid for atomic vectors\" (at least in R version 2.14.1):

v <- c(a=\'a\',b=\'b\')
v$a         


        
相关标签:
2条回答
  • 2020-12-19 09:28

    Third paragraph of the Details section of ?"$":

    ‘$’ is only valid for recursive objects, and is only discussed in the section below on recursive objects. Its use on non-recursive objects was deprecated in R 2.5.0 and removed in R 2.7.0.

    R-2.7.0 was released in April, 2008. Four years is far from "recent", but maybe you have been a few versions behind for awhile?

    0 讨论(0)
  • 2020-12-19 09:44

    I believe the reason is that the use of v$a vs. v[['a']] is considered less safe.

    EDIT: Check out this LINK for more details.

    0 讨论(0)
提交回复
热议问题