[R] Aggregating on Water Year Rather Than Calendar Year

Gabor Grothendieck ggrothendieck at myway.com
Thu Jun 17 06:32:35 CEST 2004



And here is a slightly shorter variant:

   with(as.POSIXlt(w$date.time), 1900+year+(mon>8) )

---
Gabor Grothendieck <ggrothendieck at myway.com>:

Try this to get the US water year:

require(chron)
with(month.day.year(unclass(as.Date(w$date.time))), year+(month>9))

Date: Wed, 16 Jun 2004 11:21:56 -0700 (PDT) 
From: Clint Bowman <clint at ecy.wa.gov>
To: <r-help at stat.math.ethz.ch> 
Subject: [R] Aggregating on Water Year Rather Than Calendar Year 


The US water year extends from 01 October yyyy-1 through 30 September yyyy
and is referenced by the year starting on the included 01 January yyyy. 
I'd like to be able to find the annual means for the water year. To do so 
I've taken the input date-time, which is in the usual format 

"1991-10-07 10:35:00"

changed it by:

w$d<-as.POSIXct(w$date.time)

Now I can add an offset of 92 days 

w$w.year<-as.POSIXct(w$d+7948800)

and have the years correspond to the "water year."

Now I wish to obtain some means by something like:

waterT<-aggregate(w$value[w$param.name=="Temperature"],
list(w$w.year[w$param.name=="Temperature"]),mean)

Except that I need to work on the year and being a neophyte in date 
arithmetic I'm not finding a working method.

TIA




More information about the R-help mailing list