LoslegenKostenlos starten

Calculating distance between categorical variables

In this exercise you will explore how to calculate binary (Jaccard) distances. In order to calculate distances we will first have to dummify our categories using the dummy.data.frame() from the library dummies

You will use a small collection of survey observations stored in the data frame job_survey with the following columns:

  • job_satisfaction Possible options: "Hi", "Mid", "Low"
  • is_happy Possible options: "Yes", "No"

Diese Übung ist Teil des Kurses

<Kurs>Cluster Analysis in R</Kurs>
Kurs ansehen

Übungsanweisungen

  • Create a dummified data frame dummy_survey.
  • Generate a Jaccard distance matrix for the dummified survey data dist_survey using the dist() function using the parameter method = 'binary'.
  • Print the original data and the distance matrix.
    • Note the observations with a distance of 0 in the original data (1, 2, and 3).

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Dummify the Survey Data
dummy_survey <- ___

# Calculate the Distance
dist_survey <- ___

# Print the Original Data
___

# Print the Distance Matrix
___
Code bearbeiten und ausführen