dataframe - Data.frames in R: name autocompletion? -
sorry if trivial. seeing following behaviour in r:
> mydf <- data.frame(score=5, scorescaled=1) > mydf$score ## forgot score variable capitalized [1] 1
expected result: returns null (even better: throws error).
i have searched this, unable find discussion of behaviour. able provide references on this, rationale on why done , if there way prevent this? in general love version of r little stricter variables, seems never happen...
the $
operator needs first unique part of data frame name index it. example:
> d <- data.frame(score=1, scotch=2) > d$sco null > d$scor [1] 1
a way of avoiding behavior use [[]] operator, behave so:
> d <- data.frame(score=1, scotch=2) > d[['scor']] null > d[['score']] [1] 1
i hope helpful.
cheers!
Comments
Post a Comment