将ContactID和ActivityType数据框转换为事务类

时间:2015-06-25 16:51:50

标签: r transactions sequence arules

这是我的数据框:

transtest<-structure(list(ContactID = c("003E0000008S8TcIAK", "003E0000008S8U3IAK", 
"003E0000008S8U3IAK", "003E0000008S8U4IAK", "003E0000008S8U4IAK", 
"003E0000008S8U4IAK", "003E0000008S8U4IAK", "003E0000008S8U4IAK", 
"003E0000008S8U4IAK", "003E0000008S8U4IAK"), ActivityType = c("Meeting", 
"LitOrder", "Hard Mail", "LitOrder", "Hard Mail", "Sale", "Inbound", 
"Email", "Outbound", "Left Voicemail/Message with Assistant")), .Names = c("ContactID", 
"ActivityType"), row.names = c(NA, -10L), class = c("tbl_dt", 
"tbl", "data.table", "data.frame"))

我试图通过

将其变成'交易'类
read.transactions(transtest, format = "single")

它一直给我以下错误:

Error in read.transactions(transtest, format = "single") : 
  'cols' must be a numeric or character vector of length 2 for 'single'.

我不知道为什么会发生这种情况,即使长度(colnames(transtest))= 2.我们非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

arules 文档?"transactions-class"中删除示例4:

trans1 <- as(split(transtest[,"ActivityType"], transtest[,"ContactID"]), "transactions")

inspect(trans1)
# items                                          transactionID
# 1 {Meeting}                               003E0000008S8TcIAK
# 2 {Hard Mail,                                               
#   LitOrder}                               003E0000008S8U3IAK
# 3 {Email,                                                   
#   Hard Mail,                                               
#   Inbound,                                                 
#   Left Voicemail/Message with Assistant,                   
#   LitOrder,                                                
#   Outbound,                                                
#   Sale}                                   003E0000008S8U4IAK