I'm getting in trouble transforming a dataframe object into a transaction object. I create a dataframe grouped by InvoiceNumber and the list of products separated by ',' (the dataframe then contains two columns), everything is ok,
df = read.csv('Orders.csv', sep = ';', stringsAsFactors = T)
df$Document.Date = as.Date(df$Document.Date, format = '%d/%m/%Y')
library(tidyverse)
library(plyr)
grouping_for_AA =
data.frame(
df %>%
group_by(Sales.Document, Material) %>%
dplyr::select(Sales.Document, Material, Document.Date)
)
#Create transaction data building a list of material for each sales doc
#separated by a ,
transactionData = ddply(grouping_for_AA, c('Sales.Document'),
function(df) paste(df$Material,
collapse = ',')
)
but when I use the as(data, 'transactions') function R say me to discretize input, so I use as.factor for the Product list column, but doing this each transaction becomes a factor level and no rules can be mined (clearly).
#set column InvoiceNo of dataframe transactionData
transactionData$Sales.Document <- NULL
#Change name of lists of Materials
colnames(transactionData) = 'Material'
#transform to factor
transactionData = data.frame(lapply(transactionData, factor))
#Create a transaction object: errors can be due to the package containing 'as'
trObj <- as(transactionData, "transactions")
I already tried dataframes in single and basket format, but I could not solve it.
Any Idea on how to transform a dataframe into transaction format without exporting and reloading data?