Creating the market basket transaction file
We are almost there! There is an extra step that we need to do in order to prepare our data for market basket analysis.
The association rules package requires that the data be in transaction format. Transactions can either be specified in two different formats:
- One transaction per itemset with an identifier and this shows the entire basket in one line, just as we saw with the
Groceries
data. - One single item per line with an identifier.
Additionally, you can create the actual transaction file in two different ways, by either:
- Physically writing a transactions file.
- Coercing a dataframe to transaction format.
For smaller amounts of data, coercing the dataframe to a transaction file is simpler, but for large transaction files, writing the transaction file first is preferable, since append files can be fed from large operational transaction systems. We will illustrate both ways.
Method one Coercing a dataframe to a transaction file
Now we are ready to coerce...