Using the dist() function
Using the Euclidean formula manually may be practical for 2 observations but can get more complicated rather quickly when measuring the distance between many observations.
The dist()
function simplifies this process by calculating distances between our observations (rows) using their features (columns). In this case the observations are the player positions and the dimensions are their x and y coordinates.
Note: The default distance calculation for the dist()
function is Euclidean distance
Este ejercicio forma parte del curso
Cluster Analysis in R
Instrucciones del ejercicio
- Calculate the distance between two players using the
dist()
function for the data frametwo_players
. - Calculate the distance between three players for the data frame
three_players
.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Calculate the Distance Between two_players
dist_two_players <- ___
dist_two_players
# Calculate the Distance Between three_players
dist_three_players <- ___
dist_three_players