Dear R People: The aggregate function works very well on regular time series. Is there a version for zoo or its that would take daily data and convert it to monthly, please? Thanks in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodgess at gmail.com
See ?aggregate.zoo, e.g. library(zoo) z <- zoo(1:1000, as.Date("2000-01-01") + 0:999) aggregate(z, as.yearmon, mean) or replace mean with whatever summarization you want. On Sun, Mar 7, 2010 at 5:29 PM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:> Dear R People: > > The aggregate function works very well on regular time series. > > Is there a version for zoo or its that would take daily data and > convert it to monthly, please? > > Thanks in advance, > Sincerely, > Erin > > -- > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: erinm.hodgess at gmail.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. >
x <- c(0,0,1,2,3,0,0,4,5,6) How to identify the regions of non-zeros and average c(1,2,3) and c(4,5,6) to get 2 and 5. Thanks _________________________________________________________________ Hotmail: Trusted email with Microsoft¡¯s powerful SPAM protection. [[alternative HTML version deleted]]
try this: x <- c(0,0,1,2,3,0,0,4,5,6) rl <- rle(x == 0) grp <- rep(seq_along(rl$lengths), rl$lengths) res <- tapply(x, grp, mean) res[res > 0] I hope it helps. Best, Dimitris On 3/8/2010 3:48 AM, Daren Tan wrote:> > x<- c(0,0,1,2,3,0,0,4,5,6) > > > > How to identify the regions of non-zeros and average c(1,2,3) and c(4,5,6) to get 2 and 5. > > > > Thanks > > > > _________________________________________________________________ > Hotmail: Trusted email with Microsoft??s powerful SPAM protection. > > [[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.-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014