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

saba Sa-Ba at gmx.net
Tue Feb 22 08:32:04 CET 2011



Thank you so much for your help Dennis, Pete and D Kelly!
In the meantime I tried to do a loop and came up with this:

l<-0
for (i in 0:((length(lakewil$Year)/12)-1)) {
l[i+1]<- mean(lakewil$MeanTemp[((i*12)+7):((i*12)+9)])
}
print(l)

This gives me the summer averages over the 3 months for each year...Was
this a silly way of doing this??? Your solutions look way more
like "programming" but I m having troubles understanding them.
But I guess this is exactly what I have to do now, because now as a next
step for my linear model I have to calculate an average of fire sizes
during the same time period (1980-1999). "Unfortunately" not in every year
occured fire so I cannot use the same comand as above where I always had 12
months in between. Now the dataset (named: fire) looks like this:

Year Size
1981 50.3
1984 57.3
1984 ....
1989 ....
1989 ....
1989 ...
etc

How do I calculate now a mean average fire size for the years that fires
occured? I can do it for a group of years seperately but how do I make it
better?
FSize<-mean(fire$Size[fire$Year==1981])

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



More information about the R-help mailing list