Skip to contents

This function calculates within-trait similarity as a percentage for each column in a data frame. Numeric traits use scaled mean pairwise similarity; categorical traits use the proportion of identical pairs.

Usage

compute_trait_similarity(df)

Arguments

df

A data.frame or tibble where each column is a trait vector (numeric or factor/character).

Value

A tibble with two columns:

Trait

The original column name

Similarity

Percentage similarity (0-100) for that trait

Examples

df <- data.frame(
  height = c(10, 15, 15, 20),
  color  = c("red", "blue", "red", "red")
)
compute_trait_similarity(df)
#> # A tibble: 2 × 2
#>   Trait  Similarity
#>   <chr>       <dbl>
#> 1 height         50
#> 2 color          50