I have a data frame like this one:
dataSp <- read.table( text = '
ID LATITUDE LONGITUDE
A -85 134
B 34 2
C 42 3
D 45 5
E -2 80
F -5 79',
header = TRUE )
My main objective is to generate a spatial weight matrix
this is my code so far:
data_sf <- st_as_sf(dataSp, coords = c("LONGITUDE","LATITUDE"), crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
st_is_longlat(data_sf)
coords <- st_coordinates(data_sf)
col.rel.nb <- graph2nb(relativeneigh(coords), sym=TRUE)
listaw <- spdep::nb2listw(col.rel.nb, style="W")
The problem is that listaw
doesn't include the information in ID
. How can I identify each neighbour with the ID (i.e: A,B,C,D,E,F)?