arules (version 1.7-7)

match: Value Matching

Description

Provides the generic function match() and the methods for associations, transactions and itemMatrix objects. match() returns a vector of the positions of (first) matches of its first argument in its second.

Usage

match(x, table, nomatch = NA_integer_, incomparables = NULL)

# S4 method for itemMatrix,itemMatrix match(x, table, nomatch = NA_integer_, incomparables = NULL)

# S4 method for rules,rules match(x, table, nomatch = NA_integer_, incomparables = NULL)

# S4 method for itemsets,itemsets match(x, table, nomatch = NA_integer_, incomparables = NULL)

# S4 method for itemMatrix,itemMatrix %in%(x, table)

# S4 method for itemMatrix,character %in%(x, table)

# S4 method for associations,associations %in%(x, table)

# S4 method for itemMatrix,character %pin%(x, table)

# S4 method for itemMatrix,character %ain%(x, table)

# S4 method for itemMatrix,character %oin%(x, table)

Value

match: An integer vector of the same length as x

giving the position in table of the first match if there is a match, otherwise nomatch.

%in%, %pin%, %ain%, %oin%: A logical vector, indicating if a match was located for each element of x.

Arguments

x

an object of class itemMatrix, transactions or associations.

table

a set of associations or transactions to be matched against.

nomatch

the value to be returned in the case when no match is found.

incomparables

not implemented.

Author

Michael Hahsler

Details

%in% is a more intuitive interface as a binary operator, which returns a logical vector indicating if there is a match or not for the items in the itemsets (left operand) with the items in the table (right operand).

arules defines additional binary operators for matching itemsets: %pin% uses partial matching on the table; %ain% itemsets have to match/include all items in the table; %oin% itemsets can only match/include the items in the table. The binary matching operators or often used in subset().

See Also

Other associations functions: abbreviate(), associations-class, c(), duplicated(), extract, inspect(), is.closed(), is.generator(), is.maximal(), is.redundant(), is.significant(), is.superset(), itemsets-class, rules-class, sample(), sets, size(), sort(), unique()

Other itemMatrix and transactions functions: abbreviate(), crossTable(), c(), duplicated(), extract, hierarchy, image(), inspect(), is.superset(), itemFrequencyPlot(), itemFrequency(), itemMatrix-class, merge(), random.transactions(), sample(), sets, size(), supportingTransactions(), tidLists-class, transactions-class, unique()

Examples

Run this code
data("Adult")

## get unique transactions, count frequency of unique transactions
## and plot frequency of unique transactions
vals <- unique(Adult)
cnts <- tabulate(match(Adult, vals))
plot(sort(cnts, decreasing=TRUE))

## find all transactions which are equal to transaction 10 in Adult
which(Adult %in% Adult[10])

## for transactions we can also match directly with itemLabels.
## Find in the first 10 transactions the ones which
## contain age=Middle-aged (see help page for class itemMatrix)
Adult[1:10] %in% "age=Middle-aged"

## find all transactions which contain items that partially match "age=" (all here).
Adult[1:10] %pin% "age="

## find all transactions that only include the item "age=Middle-aged" (none here).
Adult[1:10] %oin% "age=Middle-aged"

## find al transaction which contain both items "age=Middle-aged" and "sex=Male"
Adult[1:10] %ain% c("age=Middle-aged", "sex=Male")

Run the code above in your browser using DataLab