Good day everyone. I have a large dataset of 1 min wind speeds covering 5 years. How can I make an array of maximum daily values? The vectors I have are: 'VDATE' with dates in format '%Y-%m-%d' (like '1992-10-28') and 'WS' with wind speed data (same number of elements as VDATE). I want an array with 2 columns: Max daily wind speed and corresponding day. Has anyone got an elegant way of doing that? (My background is in C++ I would tend to use loops but that is not very elegant in R, isn't it?) Augusto -------------------------------------------- Augusto Sanabria. MSc, PhD. Mathematical Modeller Risk Research Group Geospatial & Earth Monitoring Division Geoscience Australia (www.ga.gov.au) Cnr. Jerrabomberra Av. & Hindmarsh Dr. Symonston ACT 2609 Ph. (02) 6249-9155
Assuming VDATE is a character vector this produces a zoo time series object. library(zoo) z <- aggregate(zoo(WS), as.Date(VDATE), max) coredata(z) and time(z) are the data vector of maximums and corresponding times, respectively. The R command: vignette("zoo") gives an introduction to zoo. Aside from zoo you could check out ?tapply, ?by and ?aggregate . On 1/16/06, Augusto.Sanabria at ga.gov.au <Augusto.Sanabria at ga.gov.au> wrote:> > Good day everyone. > > I have a large dataset of 1 min wind speeds > covering 5 years. > > How can I make an array of maximum daily values? > > The vectors I have are: 'VDATE' with dates in format > '%Y-%m-%d' (like '1992-10-28') and 'WS' with wind speed data > (same number of elements as VDATE). > > I want an array with 2 columns: Max daily wind speed and > corresponding day. > > Has anyone got an elegant way of doing that? > (My background is in C++ I would tend to use loops > but that is not very elegant in R, isn't it?) > > Augusto > > > > -------------------------------------------- > Augusto Sanabria. MSc, PhD. > Mathematical Modeller > Risk Research Group > Geospatial & Earth Monitoring Division > Geoscience Australia (www.ga.gov.au) > Cnr. Jerrabomberra Av. & Hindmarsh Dr. > Symonston ACT 2609 > Ph. (02) 6249-9155 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Thank you Gabor, the 'aggregate' function operating on zoo(WS) does the job beautifully! 'zoo' has a lot of other goodies too, great package (thanks for that too). Cheers, Augusto -------------------------------------------- Augusto Sanabria. MSc, PhD. Mathematical Modeller Risk Research Group Geospatial & Earth Monitoring Division Geoscience Australia (www.ga.gov.au) Cnr. Jerrabomberra Av. & Hindmarsh Dr. Symonston ACT 2609 Ph. (02) 6249-9155 -----Original Message----- From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] Sent: Tuesday, 17 January 2006 4:32 PM To: Sanabria Augusto Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Calculation of daily max Assuming VDATE is a character vector this produces a zoo time series object. library(zoo) z <- aggregate(zoo(WS), as.Date(VDATE), max) coredata(z) and time(z) are the data vector of maximums and corresponding times, respectively. The R command: vignette("zoo") gives an introduction to zoo. Aside from zoo you could check out ?tapply, ?by and ?aggregate . On 1/16/06, Augusto.Sanabria at ga.gov.au <Augusto.Sanabria at ga.gov.au> wrote:> > Good day everyone. > > I have a large dataset of 1 min wind speeds > covering 5 years. > > How can I make an array of maximum daily values? > > The vectors I have are: 'VDATE' with dates in format '%Y-%m-%d' (like > '1992-10-28') and 'WS' with wind speed data (same number of elements > as VDATE). > > I want an array with 2 columns: Max daily wind speed and corresponding > day. > > Has anyone got an elegant way of doing that? > (My background is in C++ I would tend to use loops > but that is not very elegant in R, isn't it?) > > Augusto > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >