From ggrothendieck at gmail.com  Sun Jun 12 21:21:59 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Sun, 12 Jun 2005 15:21:59 -0400
Subject: [Rd] by should use match.fun
In-Reply-To: <39B6DDB9048D0F4DAD42CB26AAFF0AFA64E98E@usctmx1106.merck.com>
References: <39B6DDB9048D0F4DAD42CB26AAFF0AFA64E98E@usctmx1106.merck.com>
Message-ID: <971536df050612122118e55e2f@mail.gmail.com>

On 6/12/05, Liaw, Andy <andy_liaw at merck.com> wrote:
> I don't get the point.  ?by says:

The point is that all other functions of this sort including apply, sapply,
tapply, lapply work like that so 'by' ought to as well.  

Here is the example (changed to use iris) where I noticed it.  Suppose we 
want to create a list of rows:

by(iris, row.names(iris), "(")

In every other similar function this would have worked but here we must do:

by(iris, row.names(iris), match.fun("("))




> 
> FUN a function to be applied to data frame subsets of data.
> 
> It doesn't say FUN can be a character, and by(iris, iris$Species, summary)
> works as expected.
> 
> Andy
> 
> > From: Gabor Grothendieck
> >
> > I noticed that, unlike similar functions, 'by' does not use
> > match.fun, e.g.
> >
> > > by(iris, iris$Species, "summary")
> > Error in FUN(X[[1]], ...) : couldn't find function "FUN"
> >
> > The 'by' code should have an initial line of:
> >
> > FUN <- match.fun(FUN)
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
> >
> >
> 
> 
> 
> ------------------------------------------------------------------------------
> Notice:  This e-mail message, together with any attachment...{{dropped}}



[Rd] by should use match.fun
Gabor Grothendieck