[R] linear interpolation of time series
R. Michael Weylandt <firstname.lastname@example.org>
michael.weylandt at gmail.com
Mon Dec 26 02:35:48 CET 2011
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.
On Dec 25, 2011, at 5:15 PM, David Winsemius <dwinsemius at comcast.net> wrote:
> 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?"
>> 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
>>> 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
>>> On Sat, Dec 24, 2011 at 5:39 PM, Alemtsehai Abate <abatealem at gmail.com>
>>>> 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
>>>> 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
>>>> 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
>>>> [[alternative HTML version deleted]]
>>>> R-help at r-project.org mailing list
>>>> PLEASE do read the posting guide
>>>> 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
>> 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