[R] Interpolation Problems

Steve Murray smurray444 at hotmail.com
Tue Sep 2 11:21:53 CEST 2008


Thanks Duncan - a couple of extra points... I should have perhaps pointed out that the data are on a *regular* 'box' grid (with each value currently spaced at 1 degree intervals). Also, I'm looking for something fairly simple, like a bilinear interpolation (where each new point is created based on the values of the four points surrounding it).

In answer to your question, JanAv is simply the data frame of values. And yes, you're right, I think I'll need a 2D interpolation as it's a grid with latitude and longitude values (which as an aside, I guess these need to be interpolated differently? In a 1D format??). I think you're also right in that the 'akima' package isn't suitable for this job, as it's designed for irregular grids.

Do you, or does anyone, have any suggestions as to what my best option should be?

Thanks again,

Steve



> Date: Mon, 1 Sep 2008 18:45:35 -0400
> From: murdoch at stats.uwo.ca
> To: smurray444 at hotmail.com
> CC: r-help at r-project.org
> Subject: Re: [R] Interpolation Problems
>
> On 01/09/2008 6:17 PM, Steve Murray wrote:
>> Dear all,
>>
>> I'm trying to interpolate a dataset to give it twice as many values (I'm giving the dataset a finer resolution by interpolating from 1 degree to 0.5 degrees) to match that of a corresponding dataset.
>>
>> I have the data in both a data frame format (longitude column header values along the top with latitude row header values down the side) or column format (in the format latitude, longitude, value).
>>
>> I have used Google to determine 'approxfun' the most appropriate command to use for this purpose - I may well be wrong here though! Nevertheless, I've tried using it with the default arguments for the data frame (i.e. interp <- approxfun(dataset) ) but encounter the following errors:
>>
>>> interp <- approxfun(JanAv)
>> Error in approxfun(JanAv) :
>> need at least two non-NA values to interpolate
>> In addition: Warning message:
>> In approxfun(JanAv) : collapsing to unique 'x' values
>>
>>
>> However, there are no NA values! And to double-check this, I did the following:
>>
>>> JanAv[is.na(JanAv)] <- 0
>>
>> ...to ensure that there really are no NAs, but receive the same error message each time.
>>
>> With regard to the latter 'collapsing to unique 'x' values', I'm not sure what this means exactly, or how to deal with it.
>>
>>
>> Any words of wisdom on how I should go about this, or whether I should use an alternative command (I want to perform a simple (e.g. linear) interpolation), would be much appreciated.
>
> What is JanAv? approxfun needs to be able to construct x and y values
> to interpolate; it may be that your JanAv object doesn't allow it to do
> that. (The general idea is that it will consider y to be a function of
> x, and will construct a function that takes arbitrary x values and
> returns y values matching those in the dataset, with some sort of
> interpolation between values.)
>
> If you really have longitude and latitude on some sort of grid, you
> probably want a two-dimensional interpolation, not a 1-d interpolation
> as done by approxfun. The interp() function in the akima() package does
> this, but maybe not in the format you need.
>
> Duncan Murdoch



More information about the R-help mailing list