Transforming data into transactions

Before creating a mining association rule, you need to transform the data into transactions. In the following recipe, we will introduce how to transform either a list, matrix, or data frame into transactions.

Getting ready

In this recipe, we will generate three different datasets in a list, matrix, or data frame. We can then transform the generated dataset into transactions.

How to do it...

Perform the following steps to transform different formats of data into transactions:

  1. First, you have to install and load the package arule:
    > install.packages("arules")
    > library(arules)
    
  2. You can then make a list with three vectors containing purchase records:
    > tr_list = list(c("Apple", "Bread", "Cake"),
    + c("Apple", "Bread", ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.