Learn R Programming

RulesTools (version 0.1.1)

compare_rules: Compare Association Rule Sets and Find Their Intersections

Description

Compares multiple sets of association rules, identifies intersections, and optionally displays the results or writes them to a CSV file.

Usage

compare_rules(..., display = TRUE, filename = NULL)

Value

A list containing the intersections of the provided rule sets.

Arguments

...

Named association rule sets (objects of class rules).

display

Logical. If TRUE, prints the intersection results. Default is TRUE.

filename

Character string. If provided, writes the results to a CSV file. Default is NULL.

Examples

Run this code
library(arules)
data(BrookTrout)

# Discretize the BrookTrout dataset
discrete_bt <- dtize_df(BrookTrout, cutoff = "mean")

# Generate the first set of rules with a confidence threshold of 0.5
rules1 <- apriori(
  discrete_bt,
  parameter = list(supp = 0.01, conf = 0.5, target = "rules")
)

# Generate the second set of rules with a higher confidence threshold of 0.6
rules2 <- apriori(
  discrete_bt,
  parameter = list(supp = 0.01, conf = 0.6, target = "rules")
)

# Compare the two sets of rules and display the intersections
compare_rules(
  r1 = rules1,
  r2 = rules2,
  display = TRUE
)

# If `filename = "intersections.csv"`, the data is saved in a .csv file

Run the code above in your browser using DataLab