[R] aggregate example : where is the state.region variable?

John Kane jrkrideau at yahoo.ca
Tue Aug 22 13:44:26 CEST 2006


--- Gabor Grothendieck <ggrothendieck at gmail.com>
wrote:

> It is worthwhile to note that what is being
> illustrated here is aggregating a
> numeric matrix by a factor using the
> aggregate.default method and, of course,
> a factor can't be part of a numeric matrix.

And this is exactly what the example should point out!
Of course it might have been better to use a
data.frame example with a factor to illustrate that
one can actually use aggregate with an element of the
dataset.

If we look at the example:
-------------------------------------
## Compute the averages for the variables in
'state.x77', grouped
     ## according to the region (Northeast, South,
North Central, West) that
     ## each state belongs to.
     aggregate(state.x77, list(Region = state.region),
mean)
--------------------------------------
Here, we have nothing to indicate that state.x77 is a
matrix, ( yes, one can use class to find out, assuming
one knows it exists AND thinks to use it AND
understands the implications)and nothing to explain
why the example is making a call to another dataset.  

It is pretty obvious, after a few minutes of going
"Where the blazes did "that" come from", that there is
no factor in the dataset but why there is not one and
why a call to another dataset is totally opaque.  


> 
> Of course, that is not say that the examples could
> not be improved i
> terms of clarity, simplicity and comprehensiveness
> (there is no
> example of aggregate.data.frame).

Yes they could, considerably. Two of the three
examples make a call to another dataset with no
warning or explanation. 

The time series example is, actually, pretty clear.

Thanks very much for the reply.




> >
> > --- Gabor Grothendieck <ggrothendieck at gmail.com>
> > wrote:
> >
> > > Its not part of state.x77.  Its a completely
> > > separate variable.
> > > Try ls("package:datasets") and notice its in the
> > > list
> > > or try ?state.region and note that its a
> variable in
> > > datasets.
> >
> > Thanks. I was wondering if it was going something
> like
> > that.
> >
> > However, it is a bloody stupid example, at least
> to a
> > newbie.  A call to another data.set in what is
> > supposed to be a simple example is very confusing.
> >
> > When someone is apparently illustrating a function
> > with a simple one line command I don't expect them
> to
> > call another data set, apparently create a new
> > variable (Region), and use that new variable as
> the
> > grouping variable without a word of explanation of
> > what the example is doing.
> >
> > If I sound a bit annoyed it is because I am. It
> might
> > be nice to have an example illlustate the
> funtion,not
> > do a couple of other undocumented things as well.
> > >
> > >

> wrote:
> > > > I was looking ?aggregate and ran the first
> example
> > > >
> > > >  aggregate(state.x77, list(Region =
> state.region),
> > > > mean)
> > > >
> > > > The variables in state.x77 appear to be :
> > > > > state.x77
> > > > Population Income Illiteracy Life Exp Murder
> HS
> > > Grad
> > > > Frost   Area
> > > >
> > > > Where is the "state.region" variable coming
> from?
> > > >
> > > > ______________________________________________
> > > > R-help at stat.math.ethz.ch mailing list
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > > and provide commented, minimal,
> self-contained,
> > > reproducible code.
> > > >
> > >
> >
> >
> > __________________________________________________


> protection around

> >
>



More information about the R-help mailing list