library(sf)
pts <- data.frame(ID=paste0("ob",1:15), x=runif(15, 480933, 504250),
y=runif(15, 4479433, 4535122))
pts <- st_as_sf(pts, coords = c("x", "y"),
crs = 32611, agr = "constant")
# Create distance matrix
dm <- st_distance(pts)
class(dm) <- setdiff(class(dm), "units")
attr(dm, "units") <- NULL
colnames(dm) <- pts$ID
rownames(dm) <- pts$ID
# Coerce to data.frame with TO and FROM ID's and associated distance
dm.df <- dmatrix.df(dm)
head(dm.df)
Run the code above in your browser using DataLab