Data.frames in R: name autocompletion?

前端 未结 1 951
独厮守ぢ
独厮守ぢ 2021-01-18 07:02

Sorry if this is trivial. I am seeing the following behaviour in R:

> myDF <- data.frame(Score=5, scoreScaled=1)
> myDF$score ## forgot that the Sco         


        
相关标签:
1条回答
  • 2021-01-18 07:24

    The $ operator needs only the first unique part of a data frame name to index it. So for example:

    > d <- data.frame(score=1, scotch=2)
    > d$sco
    NULL
    > d$scor
    [1] 1
    

    A way of avoiding this behavior is to use the [[]] operator, which will behave like so:

    > d <- data.frame(score=1, scotch=2)
    > d[['scor']]
    NULL
    > d[['score']]
    [1] 1
    

    I hope that was helpful.

    Cheers!

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