[R] Zoo - bug ???

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jul 13 15:00:52 CEST 2010


On Tue, Jul 13, 2010 at 7:43 AM, sayan dasgupta <kittudg at gmail.com> 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")
>
> 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

This is documented behavior (thanks to Gavin for pointing this out)
but I agree that it is undesirable and we will consider how to address
this.  In the meantime use
rollapply(a, 3, "mean")
so that it does not use rollmean or if you want NAs removed when doing
the mean calculation use na.rm = TRUE as Gavin suggested.



More information about the R-help mailing list