Entering separate column names gives values ​​in that column

Sorry if this sounds like a rookie question, but it messed me up: Are you standardly allowed to type in a partial column name and it won't throw an error, but "guess" based on the name? For example:

d = data.frame(test = c(1,2,3,4),
           tmp = c(5,6,7,8),
           tmp1 = c(9,10,11,12))

      

If I type 'd $ te' I get:

d$te
[1] 1 2 3 4

      

but if I type:

d$tm
NULL

      

I would rather get an error as I type d$tes

. Is this the default behavior and can this be changed?

+3


source to share


1 answer


This is a well-known feature. Instead, switch your data.frame to a slice:



library(tibble)
d <- as_tibble(d)
d$te

NULL
Warning message:
Unknown or uninitialised column: 'te'. 

      

+2


source







All Articles