R arules : Extract lhs items from rules

最后都变了- 提交于 2019-12-24 07:28:12

问题


I want to extract lhs items from a rule generated from arules.

For example,

{a,b,c} => {d}

I want to be able to extract a,b,c and put it in a character vector, so I can iterate and do further processing based on these items.

At the moment, I can think of parsing the set of rules, converting it to a data frame and then separate these items using character manipulation/regex. I hope there's better way of extracting these items.


回答1:


Just coerce the LHS and/or the RHS into a list:

data("Adult")
rules <- apriori(Adult, 
   parameter = list(supp = 0.5, conf = 0.9, target = "rules"))

as(lhs(rules), "list")
as(rhs(rules), "list")


来源:https://stackoverflow.com/questions/38559859/r-arules-extract-lhs-items-from-rules

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