[R] annual maximum value
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Feb 17 04:25:36 CET 2009
Try this:
> Lines <- textConnection("10/1/1989,2410
+ 10/2/1989,2460
+ 10/3/1989,2890
+ 12/31/2005,5730")
>
> library(zoo)
> library(chron)
> z <- read.zoo(Lines, header = FALSE, sep = ",", FUN = chron)
> aggregate(z, floor(as.numeric(as.yearmon(time(z)))), max)
1989 2005
2890 5730
See ?read.zoo, ?aggregate.zoo, ?as.yearmon, the 3 vignettes in the
zoo package and R News 4/1.
On Mon, Feb 16, 2009 at 10:11 PM, CJ Rubio <cjrubio at kongju.ac.kr> wrote:
>
> hi everyone!
>
> hope you can help me here.
>
> i am a new R user. what i am trying to do is to find the maximum annual
> discharge from a daily record. i have a data.frame which includes date and
> the discharge. somewhat like this..
>
> 10/1/1989 2410
> 10/2/1989 2460
> 10/3/1989 2890
> ...
> ...
> ...
> 12/31/2005 5730
>
> i have been browsing through the archives and fount out about the aggregate
> function and the zoo package. here's one of the codes i've tried
>
> DF <- read.table(data[i], sep =",") ##i have several stations to assimilate
> Date <- as.Date(as.character(DF[,3]), "%m/%d/%Y") #the date is at the 3rd
> column, obviously
> library(zoo)
> z <- aggregate(zoo(DF[,4]), cut(Date, "y"), max)
> max.discharge <- coredata(z)
> date <- time(z)
>
> the result should somehow look like this
> 11/21/1926 32600
> 4/24/1927 66500
> ...
> ...
> ..
> 4/26/2005 111000
>
> thanks for your time reading my questions,, any suggestions will be truly
> appreciated...
>
>
>
> --
> View this message in context: http://www.nabble.com/annual-maximum-value-tp22049205p22049205.html
> Sent from the R help mailing list archive at Nabble.com.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list