[R] rollapply.zoo() with na.rm=TRUE

Giles giles.heywood at cantab.net
Fri Aug 12 17:47:21 CEST 2011


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



More information about the R-help mailing list