0

I have plotted a map in R corresponding to the lat long values that i have , some lat long values are falling out of a specific region (Let's say India), is there a way to know which lat long values are those ?

rajat meena
  • 353
  • 4
  • 13
  • Welcome to SO. Please hover over the R tag - it asks for a minimal reproducible example like I provided in my answer. [Here's a guide](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610); also look at the example sections in the R help files. A good question usually provides minimal input data, the desired output data, code tries incl required packages - all copy-paste-run'able in a new/clean R session. *Why?* It makes it easier for all to follow and participate without guesswork. – lukeA Mar 01 '17 at 11:52

1 Answers1

1

Here's an example

library(sp)
spoly = SpatialPolygons(list(Polygons(list( Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2))) ), "s1")), 1L)
spoints <- SpatialPoints(matrix(c(1:4, 2:5), ncol=2))
plot(spoly)
plot(spoints, add=T)
axis(1);axis(2)

enter image description here

(ov <- spoints %over% spoly)
#  1  2  3  4 
# NA  1  1  1 
coordinates(spoints)[is.na(ov),]
# coords.x1 coords.x2 
#         1         2 

See help("%over%") for all the variations.

lukeA
  • 53,097
  • 5
  • 97
  • 100