Dear list I have two datasets, one with a large number of point coordinates, the other with spatial polygons. I want to measure the shortest distance from each point to the border of all polygons, and then store the results as a column in a data frame. (Or a vector that can be turned into a column in a data frame). The points and polygons represent different types of events, happening at different times. My next step will therefore be to add dates to each event pair in order to measure the distance in space and time. Both are stored in datasets, so that each row represents one event. I have (i think) the distance measurement in order, the problem is to get the results into the data frame in an efficient manner. I am thinking of something like a double for-loop, but can't get it to work. I am also having problems reproducing my list of spatial polygons in a simple way here, but hope that my explanation is sufficient. # Making two test areas: library(sp) w1 <- SpatialLines(list(Lines(list(Line(cbind( c(80,85,87,90,85,80), c(10,15,17,15,10,10) )))))) w2 <- SpatialLines(list(Lines(list(Line(cbind( c(65,67,76,68,65), c(30,29,24,22,30) )))))) # Test points: x = c(5, 7, 35, 28) y = c(60, 70, 90, 85) xy <- SpatialPoints(cbind(y,x)) distance <- rep(NA, 4) for (i in 1:4){distance[i] <- min(spDistsN1(coordinates(spsample((w1), n=50, type = "regular")), coordinates(xy[i,]), longlat=T))} for (i in 1:4){distance[i] <- min(spDistsN1(coordinates(spsample((w2), n=50, type = "regular")), coordinates(xy[i,]), longlat=T))} distance # What I need, is a for-loop (or something similar) that goes through the list of polygons, checks the minimum # distance to each point for each polygon, and stores the results as a vector/variable of length (number of polygons * number of points.), # so that the final result after going through all the events of both types look somewhat like "wanted". wanted <- c(2066.438, 1671.135, 1829.517, 1013.759, 2290.192, 1150.286, 2013.819, 1247.204) wanted # It sounds, and probably is, quite simple - yet I'm completely stuck... - Neru [[alternative HTML version deleted]]