addComplement: Add Complement-items to Transactions

Description Usage Arguments Value Author(s) See Also Examples

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

1
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

1
2
3
4
5
6
7
8
9
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))

Example output

Loading required package: Matrix

Attaching package: 'arules'

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

    abbreviate, write

    items                
[1] {citrus fruit,       
     semi-finished bread,
     margarine,          
     ready soups,        
     !whole milk,        
     !other vegetables}  
[2] {tropical fruit,     
     yogurt,             
     coffee,             
     !whole milk,        
     !other vegetables}  
[3] {whole milk,         
     !other vegetables}  
    items                
[1] {citrus fruit,       
     semi-finished bread,
     margarine,          
     ready soups,        
     !whole milk,        
     !other vegetables,  
     NO coffee}          
[2] {tropical fruit,     
     yogurt,             
     coffee,             
     !whole milk,        
     !other vegetables}  
[3] {whole milk,         
     !other vegetables,  
     NO coffee}          

arules documentation built on Aug. 29, 2019, 9:03 a.m.