Transforming data into transactions
Before using any rule mining algorithm, we need to transform data from the data frame format into transactions. In this example, we demonstrate how to transform a purchase order dataset into transactions with the arules
package.
Getting ready
Download the purchase_order.RData
dataset from the https://github.com/ywchiu/rcookbook/raw/master/chapter9/product_by_user.RData GitHub link.
How to do it…
Perform the following steps to create transactions:
- First, install and load the
arules
package:> install.packages("arules") > library(arules)
- Use the
load
function to load purchase orders by user into an R session:> load("product_by_user.RData")
- Last, convert the
data.table
(ordata.frame
) into transactions with theas ...
Get R for Data Science Cookbook 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.