[R-sig-Geo] Coordinate interpolation keeping NAs

Tom Gottfried tom.gottfried at o2mail.de
Wed Aug 29 06:55:22 CEST 2012


Mario,

Am 29.08.2012 01:38, schrieb Mario A. Pardo:
> Greetings,
>
> I'm sorry if this question is too basic, but I just recently moved to R.
>
> Let's say I have:
>
> lon <- c(-115.86, -115.83, NA, -115.78, -115.78, -115.75, NA, -115.68,
> -115.66)
> lat <- c( 29.76, 29.61, NA, 29.55, 29.53, 29.41, NA, 29.13, 29.09)
>
> and I need a new set of coordinates c(new.lon, new.lat) with a higher
> resolution, following some interpolation criterium, but keeping the NAs
> where they should be, according to the original data.

Think of NA as 'not available'. Thus, a coordinate vector (NA, NA) is 
that of an unknown location. The question "where it should be" does not 
seem to have a definite answer, as far as I can see.

> Is there any function similar to 'approx' that does this? I tried with
> that one but I wasn't able to avoid the interpolation over the NAs.
> Also, I would like to establish that the interpolation follows a fixed
> distance, such as a coordinate point each xx kilometers or degrees.

e.g.

approx(lon, lat, xout=seq(from=min(lon, na.rm=TRUE),
	to=max(lon, na.rm=TRUE), by=0.01))

You might also be interested in what expand.grid does.

HTH,
Tom

> Thanks a lot in advance!
>

-- 
Indo-German Centre for Sustainability
Indian Institute of Technology Madras
600 036 Chennai, India
www.igcs-chennai.org



More information about the R-sig-Geo mailing list