distance: Euclidean distance between points in 2D space

View source: R/distance.R

distanceR Documentation

Euclidean distance between points in 2D space

Description

Euclidean distance between points in 2D space

Usage

distance(xy, XY)

Arguments

xy

A numerical vector of length 2, representing a point in Cartesian space

XY

A numerical vector of length 2, representing a point in Cartesian space

Value

Returns the Euclidean distance

Source

Dave Angelini david.r.angelini@gmail.com [aut, cre]

Examples

distance(c(9,49),c(24,54))

distance(c(2,5),c(8,1))

x <- matrix(c(9,49, 24,54, 51,28, 81,54, 81,23, 86,32), ncol = 2, byrow = TRUE)

df <- data.frame(matrix(nrow = dim(x)[1], ncol = dim(x)[1]))

for (i in (1:dim(x)[1])) {
  df[i,] <- unlist(apply(x, 1, distance, XY=x[i,]))
}

df


aphanotus/borealis documentation built on Nov. 4, 2022, 8:44 p.m.