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 DataFrame into transactions.
In this recipe, we will generate three different datasets in a list, matrix, or DataFrame. We can then transform the generated dataset into transactions.
Perform the following steps to transform different formats of data into transactions:
- First, you have to install and load the
arule
package:
> install.packages("arules")> library(arules)
- You can then make a list with three vectors containing purchase records:
> tr_list = list(c("Apple", "Bread", "Cake"), + c("Apple", "Bread", "Milk"), + c("Bread", "Cake", "Milk")) > names(tr_list) = paste("Tr",c(1:3), sep = "")
- Next, you can use the
as
function to transform the DataFrame into transactions:
>...