Skip to contents

Computes similarity scores between two or more lists of factors or enums. Implements both exact matching methods for precise category equivalence and order-preserving comparisons.

Usage

same_factor(
  ...,
  method = c("exact", "order"),
  levels,
  ordered = FALSE,
  digits = 3
)

Arguments

...

Lists of categorical values (character or factor) to compare.

method

Character vector of similarity method (default: c("exact", "order")).

levels

Character vector of all allowed levels for comparison.

ordered

Logical. If TRUE, treat levels as ordered (ordinal). If FALSE, the "order" method is skipped.

digits

Number of digits to round results (default: 3).

Value

An S3 object of type "similar_factor" containing:

  • scores: Numeric similarity scores by method and comparison

  • summary: Summary statistics by method and comparison

  • methods: Methods used for comparison

  • list_names: Names of compared lists

  • levels: Levels used for categorical comparison

Examples

list1 <- list("high", "medium", "low")
list2 <- list("high", "low", "medium")

# Using unnamed lists
result1 <- same_factor(
  list1, list2,
  levels = c("low", "medium", "high"),
  ordered = TRUE
)
#>  Computed exact scores for "list1_list2" [mean: 0.333]
#>  Computed order scores for "list1_list2" [mean: 0.667]

# Using named lists for more control
result2 <- same_factor(
  "l1" = list1, "l2" = list2,
  levels = c("low", "medium", "high"),
  ordered = TRUE
)
#>  Computed exact scores for "l1_l2" [mean: 0.333]
#>  Computed order scores for "l1_l2" [mean: 0.667]