subset: Subsetting Itemsets, Rules and Transactions

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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, ...)

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

Arguments

x

object to be subsetted.

subset

logical expression indicating elements to keep.

...

further arguments to be passed to or from other methods.

Details

subset works on the rows/itemsets/rules of x. The expression given in subset will be evaluated using x, so the items (lhs/rhs/items) and the columns in the quality data.frame can be directly referred to by their names.

Important operators to select itemsets containing items specified by their labels are %in% (select itemsets matching any given item), %ain% (select only itemsets matching all given item) and %pin% (%in% with partial matching).

Value

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

Author(s)

Michael Hahsler

See Also

itemMatrix-class, itemsets-class, rules-class, transactions-class

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
data("Adult")
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"))

Example output

Loading required package: Matrix

Attaching package: 'arules'

The following objects are masked from 'package:base':

    abbreviate, write

Apriori

Parameter specification:
 confidence minval smax arem  aval originalSupport maxtime support minlen
        0.8    0.1    1 none FALSE            TRUE       5     0.1      1
 maxlen target   ext
     10  rules FALSE

Algorithmic control:
 filter tree heap memopt load sort verbose
    0.1 TRUE TRUE  FALSE TRUE    2    TRUE

Absolute minimum support count: 4884 

set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[115 item(s), 48842 transaction(s)] done [0.03s].
sorting and recoding items ... [31 item(s)] done [0.01s].
creating transaction tree ... done [0.03s].
checking subsets of size 1 2 3 4 5 6 7 8 9 done [0.12s].
writing ... [6137 rule(s)] done [0.00s].
creating S4 object  ... done [0.01s].

arules documentation built on Nov. 17, 2017, 6:02 a.m.