Learn R Programming

RandomWalker (version 0.1.0)

euclidean_distance: Distance Calculations

Description

A function to calculate the Euclidean distance between two vectors.

Usage

euclidean_distance(.data, .x, .y, .pull_vector = FALSE)

Value

A numeric Vector of ditances

Arguments

.data

A data frame

.x

A numeric vector

.y

A numeric vector

.pull_vector

A boolean of TRUE or FALSE. Default is FALSE which will augment the distance to the data frame. TRUE will return a vector of the distances as the return.

Author

Steven P. Sanderson II, MPH

Details

A function to calculate the Euclidean distance between two vectors. It uses the formula sqrt((x - lag(x))^2 + (y - lag(y))^2). The function uses augments the data frame with a new column called distance.

See Also

Other Vector Function: cgmean(), chmean(), ckurtosis(), cmean(), cmedian(), crange(), csd(), cskewness(), cvar(), kurtosis_vec(), rw_range(), skewness_vec()

Examples

Run this code
set.seed(123)
df <- rw30()
euclidean_distance(df, x, y)
euclidean_distance(df, x, y, TRUE) |> head(10)

Run the code above in your browser using DataLab