One way for doing it would be to combine the columns using paste and then use tapply to get the means.
For example: set.seed(32341) a1 = sample(c("a","b"), 100,replace = T) a2 = sample(c("a","b"), 100,replace = T) y = rnorm(100) tapply(y,paste(a1,a2), mean) ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Thu, Oct 6, 2011 at 8:40 AM, SML <paral...@lafn.org> wrote: > Hello: > > Is there a way to get a mean from values stored in different rows? > > The data looks like this: > YEAR-1, JAN, FEB, ..., DEC > YEAR-2, JAN, FEB, ..., DEC > YEAR-3, JAN, FEB, ..., DEC > > What I want is the mean(s) for just the consecutive winter months: > YEAR-1.DEC, YEAR-2.JAN, YEAR-2.FEB > YEAR-2.DEC, YEAR-3.JAN, YEAR-3.FEB > etc. > > Thanks. > > ______________________________________________ > 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. > [[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.