This function allows you to calculate the euclidean distance between two vectors
euc_dist(data, var1, var2)
data | A data frame |
---|---|
var1 | Numeric vector (generally f1). |
var2 | Numeric vectors (generally f2). |
# Create some data df <- data.frame(vowel = gl(n = 2, k = 5, labels = c('a', 'o')), var1 = rnorm(10, 10, 2), var2 = rnorm(10, 20, 2)) # Calculate euc.dist on entire data frame euc_dist(data = df, var1 = var1, var2 = var2)#> [1] 30.38112# Calculate euc.dist for each vowel library(dplyr) df %>% group_by(., vowel) %>% summarise(euc = euc_dist(., var1 = var1, var2 = var2))#> # A tibble: 2 x 2 #> vowel euc #> <fct> <dbl> #> 1 a 30.4 #> 2 o 30.4