R: Add Complement-items to Transactions

addComplement {arules} | R Documentation

## Add Complement-items to Transactions

### Description

Provides the generic function `addComplement` and the S4 methods for transactions. This function adds for given items complement items. That is it adds an artificial item to each transactions which does not contain the original item.

### Usage

    addComplement(x, labels, complementLabels=NULL)

### Arguments

`x` | an object of class `transactions`.
`labels` | character strings; item labels for which complements should be created.
`complementLabels` | character strings; labels for the artificial complement-items. If omitted then the original label is prepended by "!" to form the complement-item label.

### Value

Returns an object of class `transactions` with complement-items added.

### Author(s)

Michael Hahsler

### See Also

`transactions-class`, `merge`

### Examples

    data("Groceries")

    ## add a complement-items for "whole milk" and "other vegetables"
    g2 <- addComplement(Groceries, c("whole milk", "other vegetables"))
    inspect(head(g2, 3))

    ## use a custom label for the complement-item
    g2 <- addComplement(g2, "coffee", "NO coffee")
    inspect(head(g2, 3))

[Package arules version 1.6-2 Index]