Learn R Programming

arules (version 1.7-8)

sort: Sort Associations

Description

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

Usage

# S4 method for associations
sort(x, decreasing = TRUE, na.last = NA, by = "support", order = FALSE, ...)

Value

An object of the same class as x or a permutation vector.

Arguments

x

an object to be sorted.

decreasing

a logical. Should the sort be increasing or decreasing? (default is decreasing)

na.last

na.last is not supported for associations. NAs are always put last.

by

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.

order

should a order vector (a permutation like order()) be returned instead of the sorted associations?

...

Further arguments are ignored.

Author

Michael Hahsler

Details

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.

See Also

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

Examples

Run this code
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