[R] nearest neighbour interpolation

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Jan 31 12:26:03 CET 2003


On 31 Jan 2003, Jari Oksanen wrote:

> On Fri, 2003-01-31 at 12:47, Roger Bivand wrote:
> > On Thu, 30 Jan 2003, Matthew Oliver wrote:
> > 
> > > Dear Help List,
> > > 
> > > My name is Matt Oliver. I have been using R for about a year and find it very 
> > > helpful. However, I have a need for a function that I cannot find. I am not very 
> > > good at programming so I thought I would ask the group.
> > > 
> > Maybe this is an opportunity to explore things - they are usually feasible
> > if the motivation is sufficiently strong.
> > 
> > > I have an irregular grid of data (x = Longitude, y = Latitude). Each pair of my x,y 
> > > has a categorical value. Obviously linear or any other numerically based 
> > > interpolation on categorical data does not make sense, so I want to use a nearest 
> > > neighbor interpolation so that I can extrapolate my irregular grid to a regular grid 
> > > of Longitude and Latitude.
> > > 
> > There does not seem to be such a function at present. 
> 
> I am not sure if this is an answer to the original question, but package
> akima does the following:
> 
> Description: Linear or cubic spline interpolation for irregular
>         gridded data
> 
> which sounds like something that was asked for.

That's what was explicitly _not_ asked for: it's numerical.

Categorical nearest-neighbour interpolation can be done (easily) via
knn1 in package class, although it is a bit inefficient for very large 
grids and there are theoretically faster ways (see my 1981 book, for 
example).  You can do the grid in parts, though.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list