ddist_sf: Calculate dyadic distances between points 'i' and 'j' in a...

Description Usage Arguments Value Author(s) Examples

View source: R/ddist_sf.R

Description

This function calculates the geodesic distance between any dyads (pairs of points i and j) in a spatial dataset and stores the result in a long tibble

Usage

1
2
3
4
5
6
7
8
ddist_sf(
  data = NULL,
  id = NULL,
  crs_transform = FALSE,
  new_crs = NULL,
  diagonal = TRUE,
  duplicates = TRUE
)

Arguments

data

an object of class sf ("sf" "data.frame" or "sf" "tbl_df" "tbl" "data.frame")

id

a variable uniquely identifying geospatial points. Can be of type numeric, integer, character, or factor

crs_transform

a logical value indicating whether to transform the CRS. Defaults to FALSE

new_crs

a valid EPSG for a new CRS. See rgdal::make_EPSG() or https://epsg.org/home.html

diagonal

a logical value. Keep the diagonal component in the distance matrix with dyads (i,i) and distance zero? Defaults to TRUE

duplicates

a logical value. Keep "identical" dyads (i,j) and (j,i)? Defaults to TRUE. If set to FALSE, only one observation per dyad is kept. Note that this uses rowwise and makes the ddist function considerably more time-consuming

Value

a long tibble with dyads and dyadic distances incl. a distance unit indicator

Author(s)

Jeppe Vierø

Examples

1
2
3
4
5
6
7
8
library(tibble)
df <- tibble::tribble(
~city_name, ~idvar, ~latitude, ~longitude,
"copenhagen", 5, 55.68, 12.58,
"stockholm", 2, 59.33, 18.07,
"oslo", 51, 59.91, 10.75
) %>% sf::st_as_sf(coords = c("longitude", "latitude"), crs = 4326)
ddist_sf(data = df, id = "idvar")

jvieroe/dyadicdist documentation built on Jan. 21, 2022, 8:43 a.m.