Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

r stop guessing names when root is similar

Tags:

r

Is there an option in R that prevents it from returning values from field names with the same beginning if the one you asked for does not exist? This is causing me a fair amount of problems as my fields may or may not be present, and they have similar root names.

d <- data.frame(areallylongname = -99, y = 2, z = 0)

# How do I stop this returning a value
d$a 
#[1] -99

# it should return NULL like this
d$jjj 
# NULL
like image 502
user9774387 Avatar asked Mar 06 '23 05:03

user9774387


1 Answers

You can switch to bracket notation, which requires exact column names:

> d['a']
Error in `[.data.frame`(d, "a") : undefined columns selected

> d['y']
  y
1 2
like image 174
andrew_reece Avatar answered Mar 16 '23 00:03

andrew_reece