Hi Something like
aggregate(DF$data, list(quarters(DF$date), format(DF$date, "%Y")), mean) Regards Petr > > Hello everybody, > > I need to calculate seasonal means with temperature data for my work. > I have 70 files coming from weather stations, which looks like this for > example: > > startdate <- as.POSIXct("01/01/2006", format = "%d/%m/%Y") > enddate <- as.POSIXct("05/01/2006", format = "%d/%m/%Y") > date <- seq(from = startdate, to = enddate, by = "days",format = "%d/%m/%Y") > > DF <- data.frame(data=c(2.5,1.4,3.6,0.5,-1.2),date=date) > > With this daily data, I need to calculate seasonal means. > I mean for season: winter (January,February,March) ; Spring (April,May,June) > ; Summer(July,August,September) and Autumn(October,November,December). > > My main problem is that all my files starts and ends not the same year (some > of them starts 1st January 2006 and ends 31th december 2008, some of them > starts 1st January 2007 and ends 31th December 2011, ...). > > So not the same year, but all of them starts a 1st January and ends a 31th > December. > > I'd like first to delete (or ignore) all the first 2 months (January and > February) and the last month (December) of all my files, because I cannot > calculate a seasonal means for them (not all the 3 months). > But the problem for the first 2 months is for leap yars (with 29th > February). For example, if my file starts in 2008, the first 2 months will > not be the same length as files starting in 2007 or 2006. So I cannot just > delete the first lines of my files because there'll be a problem for these > leap years. > And then, I'd like to calculate my seasonal means on each 3 months (like I > showed you before). > For example, my object "seasonal means" should look like this: Spring 2006: > xx ; Summer 2006: xx, ....... (with xx my seasonal means). > > Have you any idea how to do this? I found functions such like "xts()" but it > need to specify a year, so in my case it couldn't work. I need to automatize > this for all my files, so it shouldn't depend on the start year. > Thanks a lot! > > > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to- > calculate-seasonal-mean-for-temperatures-tp4638639.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. ______________________________________________ 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.