Data.frames in R: autocomplete name?

Sorry if this is trivial. I see the following behavior in R:

> myDF <- data.frame(Score=5, scoreScaled=1)
> myDF$score ## forgot that the Score variable was capitalized
[1] 1

Expected result: returns NULL (even better: throws an error).

I searched for this, but could not find any discussion of this behavior. Can anyone provide any links to this, a rationale for why this is being done, and if there is any way to prevent this? All in all, I would have liked the R version, a bit more rigorous with its variables, but it seems like this will never happen ...

+4
source share
1 answer

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

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

[[]], :

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

, .

!

+5

Source: https://habr.com/ru/post/1609539/


All Articles