View source: R/unsupervised-distance.R
| tidy_gower | R Documentation |
Computes Gower distance for mixed data types (numeric, factor, ordered)
tidy_gower(data, weights = NULL)
data |
A data frame or tibble |
weights |
Optional named vector of variable weights (default: equal weights) |
Gower distance handles mixed data types:
Numeric: range-normalized Manhattan distance
Factor/Character: 0 if same, 1 if different
Ordered: treated as numeric ranks
Formula: d_ij = sum(w_k * d_ijk) / sum(w_k) where d_ijk is the dissimilarity for variable k between obs i and j
A dist object containing Gower distances
# Create example data with mixed types
car_data <- data.frame(
horsepower = c(130, 250, 180),
weight = c(1200, 1650, 1420),
color = factor(c("red", "black", "blue"))
)
# Compute Gower distance
gower_dist <- tidy_gower(car_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.