[R] by function ??

Meyners, Michael, LAUSANNE, AppliedMathematics Michael.Meyners at rdls.nestle.com
Wed Dec 9 09:05:08 CET 2009


Or, more general (if you need to include more than just one variable from TestData), something like

by(TestData, LEAID, function(x) median(x$RATIO))

Agreed, this is less appealing for the given example than Ista's code, but might help to better understand by and to generalize its use to other situations.
Michael 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Ista Zahn
> Sent: Mittwoch, 9. Dezember 2009 02:54
> To: L.A.
> Cc: r-help at r-project.org
> Subject: Re: [R] by function ??
> 
> Hi,
> I think you want
> 
> by(TestData[ , "RATIO"], LEAID, median)
> 
> -Ista
> 
> On Tue, Dec 8, 2009 at 8:36 PM, L.A. <romsa at millect.com> wrote:
> >
> > I'm just learning and this is probably very simple, but I'm stuck.
> >   I'm trying to understand the by().
> > This works.
> > by(TestData, LEAID, summary)
> >
> > But, This doesn't.
> >
> > by(TestData, LEAID, median(RATIO))
> >
> >
> > ERROR: could not find function "FUN"
> >
> > HELP!
> > Thanks,
> > LA
> > --
> > View this message in context: 
> > http://n4.nabble.com/by-function-tp955789p955789.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > R-help at r-project.org 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.
> >
> 
> 
> 
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology http://yourpsyche.org
> 
> ______________________________________________
> R-help at r-project.org 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.
> 




More information about the R-help mailing list