Skip to content
Prev 301949 / 398506 Next

how to calculate seasonal mean for temperatures

Hello,

See if this is it.


fun <- function(DF, FUN = mean){
     month <- as.integer(format(DF$date, format="%m"))
     year <- format(DF$date, format="%Y")
     month[month %in% 1:2] <- 13
     DF$season <- NA
     DF$season[month %in% 12:13] <- paste(year[month %in% 12:13], "Winter")
     DF$season[month %in% 3:5] <- paste(year[month %in% 3:5], "Spring")
     DF$season[month %in% 6:8] <- paste(year[month %in% 6:8], "Summer")
     DF$season[month %in% 9:11] <- paste(year[month %in% 9:11], "Fall")
     aggregate(data ~ season, data=DF, FUN = FUN)
}
fun(DF)


Hope this helps,

Rui Barradas

Em 01-08-2012 12:30, jeff6868 escreveu: