将 ContactID 和 ActivityType 数据框转换为交易 class
Turning ContactID and ActivityType dataframe to transaction class
这是我的数据框:
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"))
我正在尝试通过
将其变成 'transaction' class
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'.
即使 length(colnames(transtest)) = 2,我也不知道为什么会这样。非常感谢您的帮助!
遵循 arules 文档中的示例 4 ?"transactions-class"
:
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
这是我的数据框:
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"))
我正在尝试通过
将其变成 'transaction' classread.transactions(transtest, format = "single")
它一直给我以下错误:
Error in read.transactions(transtest, format = "single") :
'cols' must be a numeric or character vector of length 2 for 'single'.
即使 length(colnames(transtest)) = 2,我也不知道为什么会这样。非常感谢您的帮助!
遵循 arules 文档中的示例 4 ?"transactions-class"
:
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