假设您已经生成了规则(“规则”,在您的问题中),这里是如何对其进行子集化。基本上,您必须将数据强制转换为数据框,然后对其进行子集化。
#Here are the original rules generated with some data I created
# categories are "G", "T", "D", and "potatoe"
> inspect(rules);
lhs        rhs      support    confidencelift
1  {}  => {T}       0.3333333  0.3333333 1.0000000
2  {}  => {G}       0.5000000  0.5000000 1.0000000
3  {}  => {potatoe} 0.5000000  0.5000000 1.0000000
4  {}  => {D}       0.5000000  0.5000000 1.0000000
5  {T} => {G}       0.1666667  0.5000000 1.0000000
6  {G} => {T}       0.1666667  0.3333333 1.0000000
7  {T} => {D}       0.1666667  0.5000000 1.0000000
8  {D} => {T}       0.1666667  0.3333333 1.0000000
9  {G} => {potatoe} 0.1666667  0.3333333 0.6666667
10 {potatoe} => {G} 0.1666667  0.3333333 0.6666667
11 {potatoe} => {D} 0.3333333  0.6666667 1.3333333
12 {D} => {potatoe} 0.3333333  0.6666667 1.3333333
#Coerce into data frame
as(rules, "data.frame");
#Restrict LHS to only certain value (here, "potatoe")
rules_subset <- subset(rules, (lhs %in% c("potatoe")));
#Check to see subset rules
inspect(rules_subset);
lhs            rhs support    confidencelift
1 {potatoe} => {G} 0.1666667  0.3333333 0.6666667
2 {potatoe} => {D} 0.3333333  0.6666667 1.3333333
此方法还允许任意多个 LHS 值,而不仅仅是一个。比我之前提出的答案要容易得多。