Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread Ricardogg
You're totally right Jeff. My mistake! to use with, we write it like this: DF$season <- factor ( with ( *DF*, ifelse (( month == 12 | nonth == 1 | month == 2 ), "Win", ifelse ((month == 3 | nonth == 4 | month == 5 ) , "Spr", ifelse

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread arun
67 4   2006 Q4 2.47 A.K. - Original Message - From: jeff6868 To: r-help@r-project.org Cc: Sent: Wednesday, August 1, 2012 4:57 AM Subject: [R] how to calculate seasonal mean for temperatures Hello everybody, I need to calculate seasonal means with temperature data for my work. I h

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread Ricardogg
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 |

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread Rui Barradas
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[

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread jeff6868
It's working now! The problem was not for winter, but with the "with" you had in your object "DF$season. I got an error: invalid 'envir' argument. I removed it and now it seems to be OK. Thank you very much for your help ricardo. -- View this message in context: http://r.789695.n4.nabble.com/

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread jeff6868
Thank you both for your answers. I found a best way to delete the first 2 months (Jan + Feb) and the last month (Dec), which should work everytime: DF$year <- as.numeric(format(DF$Day, format = "%Y")) DF$month <- as.numeric(format(DF$Day, format = "%m")) # delete first 2 months for(i in DF[1,3]

Re: [R] how to calculate seasonal mean for temperatures

2012-08-01 Thread Petr PIKAL
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: > > sta

[R] how to calculate seasonal mean for temperatures

2012-08-01 Thread jeff6868
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(