On Tue, 2010-07-13 at 17:13 +0530, sayan dasgupta wrote: > Hi folks, > > I am confused whether the following is a bug or it is fine > > Here is the explanation > > a <- zoo(c(NA,1:9),1:10) > > Now If I do > > rollapply(a,FUN=mean,width=3,align="right")
mean() has argument na.rm which defaults to FALSE. As such, if NA are in the computation the mean is undefined and the answer will be NA. If you pass na.rm = TRUE to rollapply, mean ignores the NA and works on the remaining values: > rollapply(a,FUN=mean,width=3,align="right", na.rm = TRUE) 3 4 5 6 7 8 9 10 1.5 2.0 3.0 4.0 5.0 6.0 7.0 8.0 HTH G > > I get > > rollapply(a,FUN=mean,width=3,align="right") > 3 4 5 6 7 8 9 10 > NA NA NA NA NA NA NA NA > > But I shouldn't be getting NA right ? i.e for index 10 I should get > (1/3)*(9+8+7) > > Similarly > > > rollapply(a,FUN=mean,width=3) > 2 3 4 5 6 7 8 9 > NA NA NA NA NA NA NA NA > > > Zoo version : > > > installed.packages()["zoo","Version"] > [1] "1.6-3" > > > > > My machine details > > > sessionInfo() > R version 2.10.1 (2009-12-14) > i386-pc-intel32 > > locale: > [1] LC_COLLATE=English_India.1252 LC_CTYPE=English_India.1252 > LC_MONETARY=English_India.1252 LC_NUMERIC=C > [5] LC_TIME=English_India.1252 > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > other attached packages: > [1] zoo_1.6-3 rcom_2.2-1 rscproxy_1.3-1 Revobase_3.2.0 > > loaded via a namespace (and not attached): > [1] grid_2.10.1 lattice_0.18-3 tools_2.10.1 > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% ______________________________________________ R-help@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.