On Wed, 23 Mar 2005 22:16:30 +0100 (CET), [EMAIL PROTECTED] 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