[R] Performing stats on group of observations

Bert Gunter gunter.berton at gene.com
Tue Jun 25 08:07:55 CEST 2013


"... trying to figure it out" ??

Not sure what that means.Have you read "An Introduction to R."? If
not, do so now.

In any case, ?ave is made for what you want, I think (simpler than
?by). As in (if df is your data frame):

ave(df$NoFlights,df$Week, FUN= mean)

Or, better yet, using ?with and noting that mean is the default for FUN

with(df,ave(NoFlights,Week))

Cheers,
Bert




On Mon, Jun 24, 2013 at 4:53 PM, Ion Mateescu <ion.matees at gmail.com> wrote:
> This may be a simple problem but I spent most of my day today trying to
> figure it out, as I am not a programmer. I have a dataframe with
> observations from different weeks of the year, numbered. My variable
> "week" has values week1, week4, week9, etc. Not all weeks are represented.
> I need to calculate statistics and compare means for a measured variable
> (no_of_flights) :
>
> Week    NoFlights
> week1    31.00
> week1    31.00
> week1    36.00
> week1    32.00
> week1    30.00
> week1    30.00
> week1    30.00
> week2    31.00
> week2    32.00
> week1    30.00
> week1    31.00
> week1    32.00
> week23    30.00
> week23    35.00
> week57    30.00
> week1    32.00
> week1    33.00
> week1    33.00
> week2    30.00
> week2    33.00
> week1    32.00
> week1    32.00
> week1    33.00
> week23    28.00
>
> Any help is appreciated.
>
> River
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list