Skip to contents

Compare Factor Similarity Across Lists

Usage

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

Arguments

...

Lists of categorical values (character or factor) to compare. Can be named (e.g., "l1" = list1, "l2" = list2) to control list names.

method

Character vector of similarity methods. Choose from: "exact", "order" (default: all)

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"))
#>  Skipping 'order' method because levels are not explicitly ordered. Set ordered = TRUE to compute the order method.
#>  Computed exact scores for "list1_list2" [mean: 0.333]

# Using named lists for more control
result2 <- same_factor(
  "l1" = list1, "l2" = list2,
  levels = c("low", "medium", "high")
)
#>  Skipping 'order' method because levels are not explicitly ordered. Set ordered = TRUE to compute the order method.
#>  Computed exact scores for "l1_l2" [mean: 0.333]