I am doing some association rules mining in R and want to extract my results so I can build reports my results look like this:
> inspect(rules[1:3])
lhs rhs support confidence lift
1 {apples} => {oranges} 0.00029 0.24 4.4
2 {apples} => {pears} 0.00022 0.18 45.6
3 {apples} => {pineapples} 0.00014 0.12 1.8
How do i extract the "rhs" here i.e. a vector of oranges, pears and pineapples
Further how do I extract information out of the summary i.e.
> summary(rules)
The data type is "s4" and have no problem extracting when the output is in the list etc.. how do you do the equivelant? set of 3 rules
rule length distribution (lhs + rhs):sizes
2
3
Min. 1st Qu. Median Mean 3rd Qu. Max.
2 2 2 2 2 2
I want to extract the "3" from the "set of 3 rules"
I have gotten as far as using "@" What does the @ symbol mean in R?
But once i use that, how do i turn my results into a vector i.e.
inspect(rules@rhs)
1 {oranges}
2 {pears}
3 {pineapples}
becomes character vector of length 3
To answer your second question:length(rules)
Now about your first question:
library("arules")
data("Adult")
## Mine association rules.
rules <- apriori(Adult,parameter = list(supp = 0.5, conf = 0.9, target = "rules"))
summary(rules)
l = length(rules)
everything = labels(rules)
#print(everything)
cut = unlist(strsplit(everything,"=> "))[seq(2,2*l,by=2)]
print(cut)
Don't hesitate if you have a question, this might be a bit dense :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With