So I've accomplished arules model and got list of rules with different items. To find if rules contain a specific item in lhs or rhs the code is the following:rules.sub <- subset(rules, subset = items %in% "item_to_match")
.
However, my goal concerns not finding one specific item, but to match a list of items from separate csv and find all rules, which contain them. How can I do this?
Asked
Active
Viewed 164 times
0
1 Answers
0
UPD: As I've understood, it may be accomplished through subset method. However, the final code should be a bit different. The subset method throws an error, if you specify some item, which is not in list, but it can be bypassed by the following code:
1) Create find results function:
fn_findRules <- function(rules, newBasket){ arules<-subset(rules, items %in% newBasket) return (arules) }
(Thx to @lukeA , Source)
2) Creating variable with results, which uses defined function
resuslts <- fn_findRules(rules, intersect(itemLabels(rules), table_with_items_to_check))