Re: [R] an extremely simple question

From: Michael Kubovy <>
Date: Wed, 23 Jul 2008 19:43:09 -0400

A cleaner approach than attach()---because you don't need to remember to detach()---is:

my.df<-data.frame(cbind(x=runif(100), y=rnorm(100))) head(my.df)

with(my.df, plot(y~x))

Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766


On Jul 22, 2008, at 10:10 PM, milton ruser wrote:

> Hi Edna,
> I am not sure the completely right answer, but I suspect that you use
> data(df) to invoke a data.frame from the sample datasets provided
> from the
> packages available on your R system. By other side, if you have a
> data.frame
> loaded on your environent, you can use "attach" do turn the columns
> available on your environment as objects, like this.
> my.df<-data.frame(cbind(x=runif(100), y=rnorm(100)))
> head(my.df)
> plot(y~x)
> #you get error
> attach(my.df)
> plot(y~x)
> #you get the plot
> detach(my.df) # remove the x,y objects from your environment
> plot(y~x)
> #you get error again.
> On 7/22/08, Edna Bell <> wrote:
>> Hi!
>> What is the difference between using data(somedataset) vs.
>> attach(somedataset), please?
>> thanks,
>> Edna Bell

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 24 Jul 2008 - 00:34:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jul 2008 - 01:32:34 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive