[R] Newbie question: histogram
John Fox
jfox at mcmaster.ca
Thu Feb 5 03:13:29 CET 2004
Dear Doug,
At 07:13 PM 2/4/2004 -0600, Douglas Bates wrote:
>John Fox <jfox at mcmaster.ca> writes:
>
> > At 06:07 PM 2/4/2004 +0100, Martin Maechler wrote:
> > > >>>>> "JohnF" == John Fox <jfox at mcmaster.ca>
> > > >>>>> on Wed, 04 Feb 2004 09:20:43 -0500 writes:
> > >
> > > JohnF> Dear Philippe, I suppose that you want a histogram
> > > JohnF> for snow.cover and not for year. There are several
> > > JohnF> ways to proceed; two are
> > >
> > > JohnF> hist(mydata$snow.cover)
> > >
> > > JohnF> and
> > >
> > > JF> attach(mydata)
> > > JF> hist(snow.cover)
> > >
> > >Actually, attaching data frames is a bit discouraged these days.
> > >The modern R way for this (and more complicated situations) is
> > >
> > > with(mydata, hist(snow.cover) )
> > >
> >
> > Although I'm aware of (some of) the problems and possibly confusing
> > situations that can arise from attaching a data frame, I believe that,
> > especially for novice users, there's an advantage in doing so. In
> > particular, although using with() is perhaps less ambiguous, it is
> > necessary to repeat it for each command.
>
>But with any version of R compiled with the readline library and with
>the Windows GUI and with ESS for emacs you can use the arrow keys to
>retrieve the last line typed then edit it. Repeating information from
>earlier lines is not terribly difficult.
>
>I use the
> with(datafr, func(colname))
>paradigm in live sessions for introductory classes and I don't find it
>overly cumbersome.
The with() mechanism has much to recommend it. In particular, it makes you
think about where the data for a computation are coming from. I don't
believe that this is necessarily an advantage,. however, for a novice user,
who I believe will find it easier to attach a data frame, compute new
variables in the global environment, and not have to think about where the
data are coming from. Sometimes that can cause problems, but I believe that
it's usually a simpler way to proceed. On the other hand, I can see the
argument for encouraging good habits from the start.
Regards,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
More information about the R-help
mailing list