Hi. I'm comparing output from rollapply.zoo, as produced by two versions of R and package zoo. I'm illustrating with an example from a R-help posting 'Zoo - bug ???' dated 2010-07-13. My question is not about the first version, or the questions raised in that posting, because the behaviour is as documented. I'm puzzled as to why na.rm no longer is passed to mean, i.e. why element 2 is NA and not 1.5 when na.rm=TRUE, as it was before. The first example, where na.rm is not specified, and which now behaves more as one might expect prior to carefully reading the documentation, is also different from before. This is not specific to mean(), similar behaviour is shown for e.g. sum(). Have I misunderstood the documentation? Is there a way to reproduce the old behaviour with na.rm=TRUE? Thanks. Giles Version 1 ---------- R version 2.12.0 (2010-10-15) Platform: i386-pc-mingw32/i386 (32-bit) [27] zoo_1.6-4> a <- zoo(c(NA,1:9),1:10)> rollapply(a,FUN=mean,width=3)2 3 4 5 6 7 8 9 NA NA NA NA NA NA NA NA> rollapply(a,FUN=mean,width=3, na.rm = FALSE)2 3 4 5 6 7 8 9 NA 2 3 4 5 6 7 8> rollapply(a,FUN=mean,width=3, na.rm = TRUE)2 3 4 5 6 7 8 9 1.5 2.0 3.0 4.0 5.0 6.0 7.0 8.0 Version 2 ---------- R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) [25] zoo_1.7-2> a <- zoo(c(NA,1:9),1:10)> rollapply(a,FUN=mean,width=3)2 3 4 5 6 7 8 9 NA 2 3 4 5 6 7 8> rollapply(a,FUN=mean,width=3, na.rm = FALSE)2 3 4 5 6 7 8 9 NA 2 3 4 5 6 7 8> rollapply(a,FUN=mean,width=3, na.rm = TRUE)2 3 4 5 6 7 8 9 NA 2 3 4 5 6 7 8
On Fri, Aug 12, 2011 at 11:47 AM, Giles <giles.heywood at cantab.net> wrote:> Hi. > > I'm comparing output from rollapply.zoo, as produced by two versions > of R and package zoo. ?I'm illustrating with an example from a R-help > posting 'Zoo - bug ???' dated 2010-07-13. > > My question is not about the first version, or the questions raised in > that posting, because the behaviour is as documented. ?I'm puzzled as > to why na.rm no longer is passed to mean, i.e. why element 2 is NA and > not 1.5 when na.rm=TRUE, as it was before. > > The first example, where na.rm is not specified, and which now behaves > more as one might expect prior to carefully reading the documentation, > is also different from before. > > This is not specific to mean(), similar behaviour is shown for e.g. sum(). > > Have I misunderstood the documentation? ?Is there a way to reproduce > the old behaviour with na.rm=TRUE?This is a bug. Its fixed in the development version. Get the entire development version or just that one file: library(zoo) source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/rollapply.R?root=zoo") rollapply(a, FUN = mean, width = 3, na.rm = TRUE) or use this workaround: rollapply(a, FUN = function(x) mean(x, na.rm = TRUE), width = 3) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Thanks for that Gabor, it works fine from the development version you've pointed to. There is in addition a performance issue: the following benchmark ran in under 0.2s in the previous version, now consistently shows elapsed time over 14s on a Xeon with Windows. It's unaffected if I use the development version. Giles Heywood #example system.time(rollmax(x= zoo(1:10000,1:10000),k=20,align="right")) R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit)