ComeçarComece de graça

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 exercício faz parte do curso

Cluster Analysis in R

Ver curso

Instruções do exercício

  • Calculate the distance between two players using the dist() function for the data frame two_players.
  • Calculate the distance between three players for the data frame three_players.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Calculate the Distance Between two_players
dist_two_players <- ___
dist_two_players

# Calculate the Distance Between three_players
dist_three_players <- ___
dist_three_players
Editar e executar o código