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]]
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. >
thank you very much for your reply. i studied the code you gave me and tried to make adjustments to fit the requirements that i need, thank you again.. i used the following codes:> m <- read.table("D:/documents/5 stations/01014000.csv", sep =",") > z <- zoo(m[,4],as.Date(as.character(DF[,3]), "%m/%d/%Y")) > x <- aggregate(z, cut(time(z),"y"), max)i got the maximum values right using coredata(), my question now is, how can i call for the complete date (yyyy-mm-dd) and the year (yyyy) when the maximum observation for that year was observed? CJ Rubio 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-tp22049205p22051398.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- Missing fonts for tightvnc
- R package for scorecard development
- Handing connection depending on the client computer public key fingerprint
- dovecot ignoring config file contents -- istream.c problem?
- Re: Could not destroy domain, current job is remoteDispatchConnectGetAllDomainStats