[Rd] filter(x, method="recursive") when there are NA's in x messes up

From: William Dunlap <wdunlap_at_tibco.com>
Date: Mon, 18 Jul 2011 21:53:30 +0000


If x contains an NA then filter(x, f, method="recursive") puts NA's and 0.0's in the output in an odd pattern. It puts NA's in the length(f) positions ending at the position of the input NA and it puts a run of length(f) 0.0's starting at the position immediately after the input NA. The values after the 0.0's look like the recursion was restarted there.

I'd naively expect that all output values at and after the position of the input NA to be NA, but it looks like it is trying to restart the recursion. I would not expect the output values before the position of the input NA to depend on future values. Are the NA's misplaced?

> x <- c(1:4, NA, 6:9)
> cbind(x, "1"=filter(x, 0.5, method="recursive"),

+          "2"=filter(x, c(0.5, 0.0), method="recursive"),
+          "3"=filter(x, c(0.5, 0.0, 0.0), method="recursive")) 
Time Series:
Start = 1
End = 9
Frequency = 1

   x 1 2 3

1  1  1.000  1.00 1.0
2  2  2.500  2.50 2.5
3  3  4.250  4.25  NA
4  4  6.125    NA  NA
5 NA     NA    NA  NA
6  6  0.000  0.00 0.0
7  7  7.000  0.00 0.0

8 8 11.500 8.00 0.0
9 9 14.750 13.00 9.0

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 18 Jul 2011 - 21:55:09 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Jul 2011 - 22:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive