2

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.

anz
  • 987
  • 7
  • 21

1 Answers1

5

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")
Michael Hahsler
  • 2,965
  • 1
  • 12
  • 16