Learn R Programming

arules (version 1.7-2)

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

# S4 method for associations head(x, n = 6L, by = NULL, decreasing = TRUE, ...) # S4 method for associations tail(x, n = 6L, by = NULL, decreasing = TRUE, ...)

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 be returned instead of the sorted associations?

n

a single integer indicating the number of associations returned.

...

Further arguments are ignored.

Value

An object of the same class as x.

Details

sort is relatively slow for large sets of associations since it has to copy and rearrange a large data structure. Note that sorting creates a second copy of the set of associations which can be slow and memory consuming for large sets. With order = TRUE a 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

associations-class

Examples

Run this code
# NOT RUN {
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