[R] tips for looping over a category for beginner

Peter Ehlers ehlers at ucalgary.ca
Wed Jan 19 10:30:33 CET 2011


On 2011-01-18 16:27, Ben Harrison wrote:
[...snip...]

>       plot(Ozone ~ Temp, data = aq)
>
> This highlights one of the very confusing aspects of R language for me;
> is plot(x, y) the same as plot (y ~ x)? Seems to be, but maybe I'm
> missing some nuance.

plot has many methods; see with methods(plot).
If you go to the help page for plot you'll be pointed
to plot.default and plot.formula (under 'See Also').
Have a look at those to see what the difference is.
The formula method is useful in that it permits you
to set the 'data' argument (which obviates the need
for 'attach'ing.

[...snip...]

>     BTW, attach() is not usually a good idea; have a look at ?with.
>
> Great, I thought I had that trick nailed. Obviously there needs to be an
> R equivalent of l2tabu.

I wouldn't call it a sin, but I find alternatives like with()
and 'data=' much more convenient.

Peter Ehlers



More information about the R-help mailing list