
Last chance! 50% off unlimited learning
Sale ends in
Provides the method sort
to sort elements in class
associations (e.g., itemsets or rules) according to the
value of measures stored in the association's slot quality
(e.g.,
support).
# S4 method for associations
sort(x, decreasing = TRUE, na.last = NA, by = "support", order = FALSE, ...)
An object of the same class as x
or a permutation vector.
an object to be sorted.
a logical. Should the sort be increasing or decreasing? (default is decreasing)
na.last is not supported for associations. NAs are always put last.
a character string specifying the quality measure stored in
x
to be used to sort x
. If a vector of character strings is
specified then the additional strings are used to sort x
in case of
ties.
should a order vector (a permutation like order()
)
be returned instead of the sorted associations?
Further arguments are ignored.
Michael Hahsler
sort
is relatively slow for large sets of associations since it has
to copy and rearrange a large data structure.
With order = TRUE
an integer vector with the
order is returned instead of the reordered associations.
If only the top n
associations are needed then head()
using
by
performs this faster than calling sort()
and then head()
since it does it without copying and rearranging all the data. tail()
works in the same way.
Other associations functions:
abbreviate()
,
associations-class
,
c()
,
duplicated()
,
extract
,
inspect()
,
is.closed()
,
is.generator()
,
is.maximal()
,
is.redundant()
,
is.significant()
,
is.superset()
,
itemsets-class
,
match()
,
rules-class
,
sample()
,
sets
,
size()
,
unique()
data("Adult")
## Mine rules with Apriori
rules <- apriori(Adult, parameter = list(supp = 0.6))
rules_by_lift <- sort(rules, by = "lift")
inspect(head(rules))
inspect(head(rules_by_lift))
## A faster/less memory consuming way to get the top 5 rules according to lift
## (see Details section)
inspect(head(rules, n = 5, by = "lift"))
Run the code above in your browser using DataLab