[R] how to calculate seasonal mean for temperatures

Ricardogg rgonzalezgil at gmail.com
Wed Aug 1 12:56:16 CEST 2012


Here is my approximation:


# Creation of the temporal variables

DF$year <- as.numeric(format(DF$date, format = "%Y"))
DF$month <- as.numeric(format(DF$date, format = "%m"))

# For years with data from 2006 to 2008

DF_type1 <- DF [ - which (year == 2006 & month ==1 | year == 2006 & month ==
2 | year == 2008 & month == 12), ]


# For years with data from 2007 to 2011

DF_type2 <- DF [ - which (year == 2007 & month ==1 | year == 2007 & month ==
2 | year == 2011 & month == 12), ]


# Including the Season as a factor

DF$season <- factor ( with ( ifelse (( month == 1 | nonth == 2 | month == 3
), "Win", 
                             
                             ifelse ((month == 4 | nonth == 5 | month == 6 ) 
, "Spr",

ifelse ((month == 6 | nonth == 7 | month == 8 )  , "Sum", "Aut")))))

				

# To get the mean per year and season

library (plyr)


ddply ( DF, . (year, season), summarize, mean_season = mean (data))




--
View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-seasonal-mean-for-temperatures-tp4638639p4638649.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list