0

I want to subset from the df the rows in which the corresponding lat/long fall within a 100km radius from the following coordinate point:

lat = 25.70 long = 75.80 It should select at least 4 data rows, I guess by looking at the map.

library(ggplot2)
library(ggmap)

df <- data.frame(
id = as.numeric(c(1:18)), 
latitude = as.numeric(c(22.24, 23.20, 24.22, 25.02, 25.88, 26.13, 25.05, 23.93, 22.55, 26.18, 25.45, 24.01, 22.88, 26.13, 25.63, 24.43, 23.41, 26.20)),
longitude = as.numeric(c(-79.68, -79.84, -80.15, -80.01, -80.18, -78.55, -78.37, -78.24, -77.94, -76.13, -76.08, -76.13, -76.11, -75.17, -75.19, -75.29, -75.23, -75.66)))

area1 = get_map(location = c(lon = -77.9407, lat = 24.5774), zoom = 7, maptype = "satellite")

map1 = ggmap(area1, extent = "panel", legend = "bottomright")

map1+geom_point(aes(x = longitude, y = latitude), data = df, color = "#ff0000")

I am trying to do this task but unfortunately I still didn't find a way to manage this. Maybe you guys more experienced can help me to work out this data manipulation issue.

  • Why does this have 2 reopen votes? I don' see a reason for that – Jaap Dec 13 '16 at 20:24
  • I can't understand your comment. I am still waiting for an answer because I can't figure my problem out with the 2 existing answers suggested. Do you have a solution for my problem? – Jai_surf_code Dec 20 '16 at 15:06
  • What did you try? The suggested answers describe quite well how you can calculate the distance to a certain point. Based on that it should be easy to subset on a maximum distance. See also [this alternative](http://stackoverflow.com/a/31668415/2204410). – Jaap Dec 20 '16 at 21:21

0 Answers0