ddist: Create dyads of points i and j and calculate distances

Description Usage Arguments Value Author(s) Examples

View source: R/ddist.R

Description

This function calculates the geodesic distance between any dyads (pairs of points) and stores the result in a long tibble, a opposed to a wide matrix.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ddist(
  data = NULL,
  id = NULL,
  longitude = "longitude",
  latitude = "latitude",
  crs = 4326,
  crs_transform = FALSE,
  new_crs = NULL,
  diagonal = TRUE,
  duplicates = TRUE
)

Arguments

data

an object of class data.frame or tibble.

id

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

longitude

name of the numeric longitude variable. Defaults to "longitude"

latitude

name of the numeric latitude variable. Defaults to "latitude"

crs

a valid EPSG for a valid Coordinate Reference System (CRS) for your coordinates. Defaults to 4326.

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
)
ddist(data = df, id = "idvar")

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