I would like to smooth out a time series to avoid spurious jitter/error. In other words I want to do some very local robust smoothing.
I came across rollmean and rollmedian in the zoo package but ran into a problem because my vector had a NA in it. I then read somewhere that those zoo functions use runmed and therein lies the problem.
==examples==
median(c(1,1,1,2,2,2,7,NA,1,2,3,10,10,10),na.rm = TRUE)
runmed(c(1,1,1,2,2,2,7,NA,1,2,3,10,10,10),k=3)
The first line returns 2, but would have returned NA if na.rm = TRUE was not included. The second line returns Error in runmed(c(1, 1, 1, 2, 2, 2, 7, NA, 1, 2, 3, 10, 10, 10), k = 3) :. There is no way to add a na.rm argument to the line.
NA/NaN/Inf in foreign function call (arg 1)
How can I get runmed to handle the NA? By the way, rollmean returns a vector which is correct up to the NA and then returns NA for every value thereafter.
Use
na.omitOr use one of the
na.*functions from zoo (na.locf,na.approx,na.spline,na.aggregate, etc)e.g.