[R] linear interpolation of time series

David Winsemius dwinsemius at comcast.net
Mon Dec 26 00:15:51 CET 2011


On Dec 25, 2011, at 4:12 PM, Alemtsehai Abate wrote:

> Dear Michael,
> Thanks for your prompt response.
> na.approx in zoo does fine if we have some time metric. But in my  
> case, we
> don't know the time points which the data values correspond to.
> The given values in x and y are irregularly observed values at unequal
> distances in time.
> My objective is just to get 20 equally spaced values interpolating the
> given 5/9 observations (no worries about the corresponding time  
> points).

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?"

-- 
David.

>
> Tsegaye
>
> On Sat, Dec 24, 2011 at 11:46 PM, R. Michael Weylandt <
> michael.weylandt at gmail.com> wrote:
>
>> 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:
>>> Dear R users,
>>>
>>> I have two irregular time series say x and y. Each series is  
>>> supposed to
>>> cover 20 years. The data looks, for instance:
>>> x<-c(200,178, 330, 127, 420) ## only 5 observations out of the  
>>> expected
>> 20
>>> annual values
>>> y<-c(0.35,-0.18,-0.54,0.78,1.7,-1.1,0.2,1.9,0.49)### only 9  
>>> observations
>> of
>>> the expected 20
>>>
>>> I need to intepolate each of the series into equally spaced 20  
>>> points. Is
>>> there a function and library in R to do this please?
>>>
>>> Many thanks
>>>
>>> Tsegaye
>>>
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> -- 
> Alemtsehai Abate Turasie,
> Climate Theme PhD student at Exeter Climate System,www.secam.ex.ac.uk/xcs
> School of Engineering, Computing and Mathematics,
> University of Exeter,
> North Park Road, EX 4 4QF, Exeter, UK
> Harrison building room 319,
> Phone: 07405992715,
> e-mail: aatt201 at exeter.ac.uk,
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list