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).
Usage
subset(x, ...)
# S4 method for class 'itemMatrix'
subset(x, subset, ...)
# S4 method for class 'itemsets'
subset(x, subset, ...)
# S4 method for class 'rules'
subset(x, subset, ...)Details
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
Examples
data("Adult")
rules <- apriori(Adult)
#> 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 TRUE
#>
#> 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.02s].
#> checking subsets of size 1 2 3 4 5 6 7 8 9 done [0.09s].
#> writing ... [6137 rule(s)] done [0.00s].
#> creating S4 object ... done [0.01s].
## 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"))