[R] I think this modified ewma function works if anyone is interested

Leeds, Mark (IED) Mark.Leeds at morganstanley.com
Mon Dec 11 22:20:33 CET 2006


I think this modified version of ewma works for anyone who is
interested. It gets rid of any NAs, smoothes the
resulting series and then puts the NAs back in at their correct spots.
The only catch is that the input has to be a zoo object. 
Sometimes I shock myself.


ewmab<-function(x,lambda = 1, init = x[1]) {

oldindex<-index(x)

temp<-as.vector(!is.na(x))
x<-x[temp]

rval<-filter(lambda*coredata(x),filter=(1-lambda),method="recursive",ini
t=init)
nonmissingzoo<-zoo(matrix(coredata(rval),nc=1),index(x))
rval<-merge(zoo(,oldindex),nonmissingzoo)

rval

}
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}




More information about the R-help mailing list