Thursday, 3 August 2017

What is the function that allows you to avoid explicitly naming the dataset when using a variable in R?



I know there is a function for this and have used it in the past but can't seem to remember or find it.



basically I'm trying to do the following:




data(mtcars)




missing_function(mtcars)



lm(mpg ~ cyl)




where "missing_function()" allows me to use the the variables in the mtcars dataset without having to use the "$". For example: "mpg" instead of "mtcars$mpg".


Answer



Though generally frowned upon, attach will do that for you




R> attach(mtcars)
R> mpg
[1] 21 21 23 21 19 18 14 24 23 19 18 16 17 15 10 10 15 32 30 34 22 16 15 13 19 27 26 30
[29] 16 20 15 21
R>

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...