I have some lon & lat data. I would like to create new variables/columns based on the spatial features. That is for each point P
I want to set a perimeter around it and group all other points within that perimeter. Say Pa
and Pc
might be neighbours of Pb
but Pa
and Pc
might not be neighbours of each other. I am developing a model which will use data from points which are closer to point Pa
and ignore data which is far away from point Pa
, and then a different model will also be built which will use points Pc
and only consider data close to Pc
.
lon lat offense
1 -95.46866 29.87108 burglary
2 -95.31358 29.93452 robbery
3 -95.24957 29.86051 burglary
4 -95.59642 29.67272 burglary
5 -95.30692 30.00263 theft
6 -95.39709 29.70991 auto theft
7 -95.29878 29.73458 theft
8 -95.49082 29.69905 theft
9 -95.37682 29.81252 auto theft
Data:
library(ggmap)
df <- crime %>%
sample_n(20) %>%
select(lon, lat, offense)
houston <- get_map("houston, texas")
ggmap(houston) +
geom_point(data = df, aes(x = lon, y = lat, alpha = 0.5))
P
is trasitive if xPb
and bPc
, then; aPc
.