[R] problem with dates in zoo package

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 17 12:14:57 CET 2009


See ?which.max :

library(zoo)
z <- read.zoo("myfile.dat", sep = ",", format = "%m/%d/%Y")
f <- function(x) time(x)[which.max(x)]
ix <- tapply(z, floor(as.yearmon(time(z))), f)
z[ix]


On Tue, Feb 17, 2009 at 3:58 AM, CJ Rubio <cjrubio at kongju.ac.kr> wrote:
>
> i have the following code - assimilating the maximum annual discharge each
> year ffrom a daily discharge record from year 1989-2005.
>
> m <- read.table("D:/documents/5 stations/01014000.csv", sep =",")
> z <- zoo(m[,4],as.Date(as.character(m[,3]), "%m/%d/%Y"))
> x <- aggregate(z, floor(as.numeric(as.yearmon(time(z)))), max)   #code
> suggested by Gabor Grothendieck
>
> which gives me the maximum discharge each year and the year itself.. what i
> am trying now is to produce the date when the maximum discharge was observed
> in the pattern yyyy-mm-dd, like:
>
> 1988     11/9/1988      18600
> 1989      5/8/1989       49000
> ...
> 2005     4/26/2005    111000
>
> thank you all in advance...
> --
> View this message in context: http://www.nabble.com/problem-with-dates-in-zoo-package-tp22053103p22053103.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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