[R] Calculate a mean for several months for several years

D Kelly O'Day koday at processtrends.com
Tue Feb 22 06:21:56 CET 2011


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)




-- 
View this message in context: http://r.789695.n4.nabble.com/Calculate-a-mean-for-several-months-for-several-years-tp3318363p3318567.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list