Skip to content

linear interpolation of time series

5 messages · Alemtsehai Abate, R. Michael Weylandt, David Winsemius +1 more

#
zoo:::na.approx will do nicely. Though you are going to have to supply
some sort of time metric or it won't know where interpolations should
happen.

Something like this is my usual route:

x <- zoo(1:5, Sys.Date() + 2*(1:5))

x.new <- zoo(NA, seq(min(time(x)), to =  max(time(x)), by = "day"))

x.new[time(x)] <- x

na.approx(x.new)

Michael
On Sat, Dec 24, 2011 at 5:39 PM, Alemtsehai Abate <abatealem at gmail.com> wrote:
#
On Dec 25, 2011, at 4:12 PM, Alemtsehai Abate wrote:

            
Without some sort of constraint the question is far too vague  
mathematically to support advice. And without context for the source  
of these numbers there is no scientific support either. So we are  
devolving to that level of "the plural of anecdote not being  
data.". ... ie. "  I've got five points... please tell me what pattern  
they represent?"
Agreed with David - if you don't even know how many points there are between your observations, you can't do any meaningful interpolation. 

Perhaps something like

out <- seq(min(x), max(x), length.out = 20) 

But that has it's own presumptions. 

Perhaps talk a little about your data and how the missingness arises...it also might be easier to leave the NA's in depending on the subsequent analysis you intend to run.

Michael
On Dec 25, 2011, at 5:15 PM, David Winsemius <dwinsemius at comcast.net> wrote: