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]]
Hi Ion: Here's something that might work for you> flight.df <- read.table(file="clipboard",header=TRUE) > by(flight.df$NoFlights,flight.df$Week,summary)flight.df$Week: week1 Min. 1st Qu. Median Mean 3rd Qu. Max. 30.00 30.75 32.00 31.75 32.25 36.00 ------------------------------------------------------------ flight.df$Week: week2 Min. 1st Qu. Median Mean 3rd Qu. Max. 30.00 30.75 31.50 31.50 32.25 33.00 ------------------------------------------------------------ flight.df$Week: week23 Min. 1st Qu. Median Mean 3rd Qu. Max. 28.0 29.0 30.0 31.0 32.5 35.0 ------------------------------------------------------------ flight.df$Week: week57 Min. 1st Qu. Median Mean 3rd Qu. Max. 30 30 30 30 30 30>Hope this helps! Sincerely, Erin On Mon, Jun 24, 2013 at 6:53 PM, Ion Mateescu <ion.matees@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@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. >-- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess@gmail.com [[alternative HTML version deleted]]
"... 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