[R] Zoo - bug ???
Joshua Ulrich
josh.m.ulrich at gmail.com
Tue Nov 30 15:54:16 CET 2010
Hi Christian,
On Tue, Nov 30, 2010 at 8:22 AM, clangkamp <christian.langkamp at gmxpro.de> wrote:
>
> I am not sure whether this is 100 % related, but I also get some unexpected
> behaviour with NA and rollapply:
> In the following example I would expect in Line 3 to see a 1 instead of an
> NA (mean out of [1, NA, NA]
> What do you think ?
>
I'm confused. Why do you expect the 3rd element to have a non-NA
value when you've specified width=4? The first 3 elements will be
missing (or NA if na.pad=TRUE) when width=4 and align="right".
The results are as you expect when width=3:
> A1b <- rollapply(A1a,4,mean, na.rm=TRUE, na.pad=FALSE, align="right")
> cbind(A1a,A1b)
A1a A1b
1 NA NA
2 NA NA
3 1 1.0
4 2 1.5
5 3 2.0
6 4 3.0
7 5 4.0
8 6 5.0
9 NA 5.5
10 NA 6.0
HTH,
--
Joshua Ulrich | FOSS Trading: www.fosstrading.com
>
>> mean(c(1,NA, NA), na.rm=TRUE)
> [1] 1
>
>> A1a<-zoo(c(NA, NA, 1,2,3,4,5,6, NA, NA))
>> A1b<-rollapply(A1a,4,mean, na.rm=TRUE, na.pad=FALSE, align="right")
>> View(cbind(A1a,A1b))
>> cbind(A1a,A1b)
> A1a A1b
> 1 NA NA
> 2 NA NA
> 3 1 NA
> 4 2 1.5
> 5 3 2.0
> 6 4 2.5
> 7 5 3.5
> 8 6 4.5
> 9 NA 5.0
> 10 NA 5.5
>
> -----
> Christian Langkamp
> christian.langkamp-at-gmxpro.de
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Zoo-bug-tp2287282p3065458.html
> Sent from the R help mailing list archive at Nabble.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.
>
More information about the R-help
mailing list