Skip to content
Prev 302863 / 398503 Next

How to find data in a map according to coordinates?

Hello,

You have three coordinates but the problem description only envolves two 
of them, x and y. The code below is valid for any number of dimensions.


min.dist <- function(p, coord){
     which.min( colSums((t(coord) - p)^2) )
}

# Use set.seed to have reproducible simulations
set.seed(1)
test <- data.frame(x=c(1:10),y=c(41:50),temperature=rnorm(1:10))

imin <- min.dist(c(4, 46), test[, 1:2])
test[imin, "temperature"]

Hope this helps

Rui Barradas

Em 09-08-2012 07:56, jeff6868 escreveu: