Re: [Rd] interp.surface() error (PR#7745)

From: <murdoch_at_stats.uwo.ca>
Date: Wed 23 Mar 2005 - 21:35:07 GMT


On Wed, 23 Mar 2005 22:16:30 +0100 (CET), takahama@andrew.cmu.edu wrote :

>R version: 2.001
>OS: Windows XP SP2
>
>When I use the interp.surface() function, on occasion I have encountered
>the following error message:
>
>Error in interp.surface(a, loc) : subscript out of bounds
>
>Since it is somewhat dependent on the data set, I cannot say exactly in
>which cases these occur, but I believe I have found the problem and a
>solution for it:
>
>The scaling calculations in the code,
> lx <- ((nx - 1) * (loc[, 1] - xa))/xr + 1
> ly <- ((ny - 1) * (loc[, 2] - ya))/yr + 1
>can lead to numerical error, so in the following lines
> lx1 <- ifelse(lx == nx, nx - 1, trunc(lx))
> ly1 <- ifelse(ly == ny, ny - 1, trunc(ly))
>the equality statements which are the first arguments to the IF-ELSE
>statements return false when they are supposed to be true. I believe the
>remedy is to simply avoid absolute equalities, as in the following example
>(which has worked for my problem):
> lx1 <- ifelse(abs(lx - nx) < 1e-10, nx - 1, trunc(lx))
> ly1 <- ifelse(abs(ly - ny) < 1e-10, ny - 1, trunc(ly))
>
>I hope this is an appropriate posting for an error report. Thank you very
>much for your hard work,

I think

ifelse(lx >= nx, nx - 1, trunc(lx))
ifelse(ly >= ny, ny - 1, trunc(ly))

would probably be a better fix, but I'd really like to see an example of this in action. Could you email me a dataset where you see it?

Duncan Murdoch



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Mar 24 08:38:02 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:02 GMT