[R] function by

Thomas Lumley tlumley at u.washington.edu
Thu Sep 30 19:25:14 CEST 2004


On Thu, 30 Sep 2004, Witold Eryk Wolski wrote:

> ?by
> FUN: a function to be applied to data frame subsets of 'data'.
>
> ...: further arguments to 'FUN'.
>
>
> by (SS, year, sum)

Quite likely
    by(SS, year, function(these) sum(these$SStot))
will be needed.  There are probably some columns for which sum() won't 
work

 	-thomas

> /E
>
>
>
> Emilie Berthiaume wrote:
>
>> Hi,
>> 
>> I'm just getting started with R and I'm having problems with some simple
>> operations: I want to get the the sum of the column "SStot" for each year 
>> using
>> the function by.  The data set is named "SS".  I've tried this:
>> 
>> by (SS, year, sum(SStot))
>> 
>> and it's not working.  Is it because there's a different number of rows for 
>> each
>> year?  How else can I do this?
>> 
>> --
>> Emilie Berthiaume
>> Graduate student
>> Biology Departement
>> Université de Sherbrooke
>> 2500 boul. de l'Université
>> Sherbrooke, Québec
>> J1K 2R1 CANADA
>> 
>> Tél: 1-819-821-8000 poste 2059
>> Fax: 1-819-821-8049
>> Emilie.Berthiaume at USherbrooke.ca
>> 
>> ______________________________________________
>> 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
>> 
>> 
>
>
> -- 
> Dipl. bio-chem. Witold Eryk Wolski         MPI-Moleculare Genetic
> Ihnestrasse 63-73 14195 Berlin           _
> tel: 0049-30-83875219                   'v'
> http://www.molgen.mpg.de/~wolski       /   \
> mail: witek96 at users.sourceforge.net  ---W-W----
>     wolski at molgen.mpg.de
>
> ______________________________________________
> 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
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle


More information about the R-help mailing list