From ggrothendieck at gmail.com  Thu Sep 27 18:51:45 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 27 Sep 2007 12:51:45 -0400
Subject: [Rd] Aggregate factor names
In-Reply-To: <7C6C5FCB-6050-4E1D-9406-137989F834B9@dal.ca>
References: <375E8B77-0436-472C-9F85-C56B46DFFEE9@DAL.CA>
	<971536df0709270906g2227637ev7faabf8daf05be4@mail.gmail.com>
	<7C6C5FCB-6050-4E1D-9406-137989F834B9@dal.ca>
Message-ID: <971536df0709270951n636f1d4fr1f3485409e353375@mail.gmail.com>

You can do this too:

aggregate(iris[-5], iris["Species"], mean)

or this:

with(iris, aggregate(iris[-5], data.frame(Species), mean))

or this:

attach(iris)
aggregate(iris[-5], data.frame(Species), mean)

The point is that you already don't have to write x = x.  The only
reason you are writing it that way is that you are using list instead
of data.frame.  Just use data.frame or appropriate indexing as shown.

On 9/27/07, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> Understood, but my point is that the naming I suggest should be the
> default. One should not be 'punished' for being explicit in calling
> aggregate.
>
>
> On 27-Sep-07, at 1:06 PM, Gabor Grothendieck wrote:
>
> > You can do this:
> >
> > aggregate(iris[-5], iris[5], mean)
> >
> >
> > On 9/27/07, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
> >> Hi all,
> >>
> >> A suggestion derived from discussions amongst a number of R users in
> >> my research group: set the default column names produced by aggregate
> >> () equal to the names of the objects in the list passed to the 'by'
> >> object.
> >>
> >> ex. it is annoying to type
> >>
> >> with(
> >>        my.data
> >>        ,aggregate(
> >>                my.dv
> >>                ,list(
> >>                        one.iv = one.iv
> >>                        ,another.iv = another.iv
> >>                        ,yet.another.iv = yet.another.iv
> >>                )
> >>                ,some.function
> >>        )
> >> )
> >>
> >> to yield a data frame with names = c
> >> ('one.iv','another.iv','yet.another.iv','x') when this seems more
> >> economical:
> >>
> >> with(
> >>        my.data
> >>        ,aggregate(
> >>                my.dv
> >>                ,list(
> >>                        one.iv
> >>                        ,another.iv
> >>                        ,yet.another.iv
> >>                )
> >>                ,some.function
> >>        )
> >> )
> >>
> >> --
> >> Mike Lawrence
> >> Graduate Student, Department of Psychology, Dalhousie University
> >>
> >> Website: http://memetic.ca
> >>
> >> Public calendar: http://icalx.com/public/informavore/Public
> >>
> >> "The road to wisdom? Well, it's plain and simple to express:
> >> Err and err and err again, but less and less and less."
> >>        - Piet Hein
> >>
> >> ______________________________________________
> >> R-devel at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
>
> --
> Mike Lawrence
> Graduate Student, Department of Psychology, Dalhousie University
>
> Website: http://memetic.ca
>
> Public calendar: http://icalx.com/public/informavore/Public
>
> "The road to wisdom? Well, it's plain and simple to express:
> Err and err and err again, but less and less and less."
>        - Piet Hein
>
>
>



[Rd] Aggregate factor names
Gabor Grothendieck