[R-sig-teaching] Problem with "attach"

Richard M. Heiberger rmh at temple.edu
Mon Dec 29 01:10:26 CET 2014


Steven,

It is strongly recommended that you don't use attach.
Use the data= argument.  This works.

my.data <- data.frame(contributions=c(
                        1000,1500,1200,1800,1600,1100,1000,1250,
                        1500,1800,2000,1200,2000,1700,1800,1900,
                        0900,1000,1200,1500,1200,1550,1000,1100),
                      approach=factor(c(
                        1,1,1,1,1,1,1,1,
                        2,2,2,2,2,2,2,2,
                        3,3,3,3,3,3,3,3)))

bwplot(contributions ~ approach, data=my.data) ## lattice graphics

plot(contributions ~ approach, data=my.data)   ## base graphics

Rich

On Sun, Dec 28, 2014 at 6:35 PM, Steven Stoline <sstoline at gmail.com> wrote:
> Dear All:
>
> I do have problem with attach. I believe that I am doing the data.frame
> correctly. But it seems that I do have problem with the "attach" statement.
>
> here is what I am doing:
>
>
> contributions<-c(1000,1500,1200,1800,1600,1100,1000,1250,1500,1800,2000,1200,2000,1700,1800,1900,900,1000,1200,1500,1200,1550,1000,1100)
> contributions
>
> ### approach<-c(rep(1,8), rep(2,8), rep(3,8))
>
> approach<-c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3)
> approach
>
> n<-length(contributions)
>
> donations <- data.frame(approach=approach,contributions=contributions)
> donations
>
>
> attach(donations)
>
>
>
> the code "*plot(approach~contributions)* " should yield the box-plots, but
> it does not.
>
>
>
>
>
> This what I got from R:
> ================
>
>> attach(donations)
> The following objects are masked _by_ .GlobalEnv:
>
>     approach, contributions
> The following objects are masked from donations (position 3):
>
>     approach, contributions
> The following objects are masked from donations (position 5):
>
>     approach, contributions
> The following objects are masked from donations (position 6):
>
>     approach, contributions
> The following objects are masked from donations (position 8):
>
>     approach, contributions
> The following objects are masked from donations (position 10):
>
>     approach, contributions
> The following objects are masked from donations (position 12):
>
>     approach, contributions
> The following objects are masked from donations (position 13):
>
>     approach, contributions
> The following objects are masked from donations (position 14):
>
>     approach, contributions
> The following objects are masked from donations (position 15):
>
>     approach, contributions
> The following objects are masked from donations (position 16):
>
>     approach, contributions
>
>
>
> Any help will be highly appreciated.
> with many thanks
> Steve
>
>
>
> --
> Steven M. Stoline
> 1123 Forest Avenue
> Portland, ME 04112
> sstoline at gmail.com
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching



More information about the R-sig-teaching mailing list