Why is it not advisable to use attach() in R, and what should I use instead?

后端 未结 4 1841
滥情空心
滥情空心 2020-11-22 12:40

Let\'s assume that we have a data frame x which contains the columns job and income. Referring to the data in the frame normally requi

4条回答
  •  -上瘾入骨i
    2020-11-22 12:42

    If you execute attach(data) multiple time, eg, 5 times, then you can see (with the help of search()) that your data has been attached 5 times in the workspace environment. So if you de-attach (detach(data)) it once, there'll still be data present 4 times in the environment. Hence, with()/within() are better options. They help create a local environment containing that object and you can use it without creating any confusions.

提交回复
热议问题