CommencerCommencer gratuitement

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

Cet exercice fait partie du cours

Cluster Analysis in R

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Calculate the Distance Between two_players
dist_two_players <- ___
dist_two_players

# Calculate the Distance Between three_players
dist_three_players <- ___
dist_three_players
Modifier et exécuter le code