> Date: Fri, 21 Feb 2003 11:43:53 +1300 > From: Jeremy Z Butler <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: [R] group means > > Hi, > Any hints on how I would generate the means of each 5 number group in a > column of numbers in data.frame form. i.e. get mean of first five in column > and then mean of second five in column etc. etc. >
One way to do what you want is to create a grouping variable and add it to your data frame as a factor, and then use tapply. e.g., assuming your dataframe "d" with column "x" has a number of rows divisible by 5, use d$grp<-gl(dim(d)[1]/5,5) tapply(d$x,d$grp,"mean") J.R. Lockwood 412-683-2300 x4941 [EMAIL PROTECTED] http://www.rand.org/methodology/stat/members/lockwood/ ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
