I would like to calculate the distances between each polygon in a shapefile using the sf package (or other packages that potentially works). I prefer the distance to be the maximum or minimum distance (as I don't know how to set up these parameters). As an example, suppose there are three polygons in a shapefile namely polygon A, B and C, the result I would like to get would be a data frame that says the distance between A to B, A to C, B to C.
For an example shapefile, you can use the sf inbuilt example shapefile by code below:
library(sf)
counties <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = T)
Any hint will be much appreciated :) Thanks in advance for your help!