Skip to contents

Provides the generic function merge() and the methods for itemMatrix and transactions to add new items to existing data.

Usage

merge(x, y, ...)

# S4 method for class 'itemMatrix'
merge(x, y, ...)

# S4 method for class 'transactions'
merge(x, y, ...)

Arguments

x

an object of class itemMatrix or transactions.

y

an object of the same class as x (or something which can be coerced to that class).

...

further arguments; unused.

Value

Returns a new object of the same class as x with the items in y added.

Author

Michael Hahsler

Examples

data("Groceries")

## create a random item as a matrix
randomItem <- sample(c(TRUE, FALSE), size = length(Groceries), replace = TRUE)
randomItem <- as.matrix(randomItem)
colnames(randomItem) <- "random item"
head(randomItem, 3)
#>      random item
#> [1,]        TRUE
#> [2,]       FALSE
#> [3,]       FALSE

## add the random item to Groceries
g2 <- merge(Groceries, randomItem)
nitems(Groceries)
#> [1] 169
nitems(g2)
#> [1] 170
inspect(head(g2, 3))
#>     items                 
#> [1] {citrus fruit,        
#>      semi-finished bread, 
#>      margarine,           
#>      ready soups,         
#>      random item}         
#> [2] {tropical fruit,      
#>      yogurt,              
#>      coffee}              
#> [3] {whole milk}