Thanks for the reply Peter.

On 18 January 2011 22:52, Peter Ehlers <ehlers@ucalgary.ca> wrote:

> Since you don't provide data, let's borrow from the
> help(droplevels) page:
>

I had no joy with my R install finding droplevels exactly, but found this
instead:
> ??droplevels
gdata::drop.levels      Drop unused factor levels
Is that the same?


> aq <- transform(airquality,
>        Month = factor(Month, labels = month.abb[5:9]))
>
> str(aq)
> #'data.frame':   153 obs. of  6 variables: |
> # $ Ozone  : int  41 36 12 18 NA 28 23 19  |
> # $ Solar.R: int  190 118 149 313 NA NA 29 |
> # $ Wind   : num  7.4 8 12.6 11.5 14.3 14. | etc
> # $ Temp   : int  67 72 74 62 56 66 65 59  |
> # $ Month  : Factor w/ 5 levels "May","Jun |
> # $ Day    : int  1 2 3 4 5 6 7 8 9 10 ... |
>
> Now see if the following give you some R inspiration:
>
>  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(Ozone ~ Temp, data = aq, subset = {Month == "Sep"})
>
>  boxplot(Ozone ~ Month, data = aq)
>
>  boxplot(Ozone ~ Month, data = aq,
>                        subset = {Month != "Aug"})
>
>  boxplot(Ozone ~ Month, data = aq,
>     subset = {!(Month %in% c("Jul", "Aug"))})
>
>  boxplot(Ozone ~ Month,
>     data = droplevels(subset(aq, subset = {Month != "Aug"})))
>
>  boxplot(Ozone ~ Month,
>     data = droplevels(subset(aq, !(Month %in% c("Jul", "Aug")))))
>

Thanks for these examples, they mostly make sense!


>
> 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.

Cheers,
Ben.

	[[alternative HTML version deleted]]

