--- On Tue, 2/22/11, D Kelly O'Day <ko...@processtrends.com> wrote:
> From: D Kelly O'Day <ko...@processtrends.com> > Subject: Re: [R] Calculate a mean for several months for several years > To: r-help@r-project.org > Received: Tuesday, February 22, 2011, 12:21 AM > > Pete > > The original question "I would like to calculate the > average of the mean > temperature for the summer months (Juli, August, September) > for each of the > 20 years" > > Your codes gives mean for each of the 3 months, not for the > 20 summers. > > Here is a way to get the summer average for each of the 20 > years: > > set.seed = 1 > d=data.frame(year=rep(1980:1999,each=12), > month=rep(1:12,20), meanTemp = > rnorm(240,10,5)) > sum_d <- subset(d, d[,2]>=7 & temp_df[,2] > <=9) > aggregate(meanTemp ~ year, data = sum_d, mean) Where did temp_df come from? Should it not be: sum_d <- subset(d, d[,2]>=7 & d[,2] <=9) ______________________________________________ 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.