Skip to content

Fast way of replacing missing data points in xts object

3 messages · Wolfgang Wu, Brian G. Peterson, Benczik Sandor

#
I am sorry if this wasn't clear enough. The interpolation isn't the problem. The logic for it is stated below. I am looking for a faster/more elegant way to execute the loop and if statements given the logic in the loop.

--- Brian G. Peterson <brian at braverock.com> schrieb am Do, 19.11.2009:
#
I looks like with the Near and Far series you're doing linear 
interpolation, and with the VIX series you're doing  locf  interpolation.

Even if my glance at your code is incorrect, studying the way in which 
the na interpolation functions are implemented in zoo is likely to be 
your best way of improving your own code.
wob wu wrote:

  
    
#
For the first one try something along the lines:

replacement.far <- lag(SP$Far) + SP$Near - lag(SP$Near)
SP$Far[is.na(SP$Far)] <- replacement.far[is.na(SP$Far)]

The last one is simple locf as Brian said. 

HTH,
Sandor
On Thu, 2009-11-19 at 14:06 +0000, wob wu wrote: