subset {arules}R Documentation

Subsetting Itemsets, Rules and Transactions


Provides the generic function subset() and methods to subset associations or transactions (itemMatrix) which meet certain conditions (e.g., contains certain items or satisfies a minimum lift).


subset(x, ...)

## S4 method for signature 'itemMatrix'
subset(x, subset, ...)

## S4 method for signature 'itemsets'
subset(x, subset, ...)

## S4 method for signature 'rules'
subset(x, subset, ...)



object to be subsetted.


further arguments to be passed to or from other methods.


logical expression indicating elements to keep.


subset() finds the rows/itemsets/rules of x that match the expression given in subset. Parts of x like items, lhs, rhs and the columns in the quality data.frame (e.g., support and lift) can be directly referred to by their names in subset.

Important operators to select itemsets containing items specified by their labels are


An object of the same class as x containing only the elements which satisfy the conditions.


Michael Hahsler


rules <- apriori(Adult)

## select all rules with item "marital-status=Never-married" in 
## the right-hand-side and lift > 2
rules.sub <- subset(rules, subset = rhs %in% "marital-status=Never-married" 
    & lift > 2)

## use partial matching for all items corresponding to the variable
## "marital-status"
rules.sub <- subset(rules, subset = rhs %pin% "marital-status=")

## select only rules with items "age=Young" and "workclass=Private" in
## the left-hand-side
rules.sub <- subset(rules, subset = lhs %ain% 
    c("age=Young", "workclass=Private"))

[Package arules version 1.7-7 Index]