tidy_gower: Gower Distance Calculation

View source: R/unsupervised-distance.R

tidy_gowerR Documentation

Gower Distance Calculation

Description

Computes Gower distance for mixed data types (numeric, factor, ordered)

Usage

tidy_gower(data, weights = NULL)

Arguments

data

A data frame or tibble

weights

Optional named vector of variable weights (default: equal weights)

Details

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

Value

A dist object containing Gower distances

Examples

# 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)


tidylearn documentation built on Feb. 6, 2026, 5:07 p.m.