-->

matching transaction with %in% in arules package R

2019-08-12 05:52发布

问题:

I need to find transactions matching some rules. The following code used to work, but now R recognise %in% from the base package instead from arules.

matchRules=function(rules,transactions){
  id.match=which(transactions %in% rules)
  matchedTrx=transactions[id.match]
  summary(matchedTrx)

  return(matchedTrx)
}

I tried arules::%in% but it doesn't work.

If I use:

id.match=which(transactions arules::%in% rules)

I get Error:

unexpected symbol in "id.match=which(transactions arules"

Thanks for your help.

回答1:

Try this instead of %in%, I hope it helps

library(arules)    
st <- supportingTransactions(rules, transactions)
Transaction_IDs <- as(st,"list")


回答2:

Try this:

which(arules::'%in%'(transactions,rules))


标签: r match arules