这是我的数据框:
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.我们非常感谢您的帮助!
答案 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