Learn R Programming

arules (version 1.0-12)

aggregate: Aggregate Items Into Item Groups

Description

Provides the generic functions and the S4 methods for aggregating items in rules and itemsets. Often an item hierarchy is available for datasets used for association rule mining. For example in a supermarket dataset items like "bread" and "beagle" might belong to the item group (category) "baked goods". The aggregate methods replaces items in transactions, itemsets or rules with item groups as specified by the user.

Usage

## S3 method for class 'itemMatrix':
aggregate(x, itemLabels)
## S3 method for class 'itemsets':
aggregate(x, itemLabels)
## S3 method for class 'rules':
aggregate(x, itemLabels)

Arguments

x
an transactions, itemsets or rules object.
itemLabels
a vector of character strings (factor) of the same length as items in x. Items receiving the same item label will be aggregated.

Value

  • This method returns an object of the same class as x encoded with a number of items equal to the number of unique values in itemLabels. Note that for associations (itemsets and rules) the number of associations in the returned set will most likely be reduced since several associations might map to the same aggregated association and aggregate returns a unique set. If several associations map to a single aggregated association then the quality measures of one of the original associations is randomly chosen.

Examples

Run this code
data("Groceries")

## Groceries contains a hierarchy stored in itemInfo
head(itemInfo(Groceries))
level1 <- itemInfo(Groceries)[["level1"]]
levels(level1)


## Aggregate transactions
aggregate(Groceries, level1)

## Aggregate rules
rules <- apriori(Groceries, parameter=list(supp=0.005, conf=0.5))
rules
aggregate(rules, level1)

Run the code above in your browser using DataLab