matching transaction with %in% in arules package R

孤街浪徒 提交于 2019-12-11 07:55:33

问题


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))


来源:https://stackoverflow.com/questions/17805578/matching-transaction-with-in-in-arules-package-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!