如何读取 R feom 数据框中的事务?
Posted
技术标签:
【中文标题】如何读取 R feom 数据框中的事务?【英文标题】:How to read.transactions in R feom data frame? 【发布时间】:2019-10-07 12:38:24 【问题描述】:我有以下任务。我有 50M 的交易行。我无法将其导出到 .txt 文件,但我与 Hive 有连接,并且我创建了包含事务的表: Transcation_id 项目 1个 1乙 1℃ 2个 2个
我不能用
order_trans <- read.transactions(
file = "(...)/trans2019.csv",
format = "single",
header=TRUE,
sep = ",",
cols=c("trans_id","item"),
rm.duplicates = T,
encoding = "UTF-16LE")
因为它减少了交易。
我也想做同样的事情,但是代替“文件”,我想放置我的数据框(trans_id,item),但它不起作用。 我也试过了:
trans = as(data.frame,"transactions")
但是先验算法给了我错误的规则
APPLE--> transaction_ID
谁能帮我解决这个问题?
【问题讨论】:
【参考方案1】:以下是手册页中的解决方案(请参阅“?交易”):
## example 4: creating transactions from a data.frame with
## transaction IDs and items (by converting it into a list of transactions first)
a_df3 <- data.frame(
TID = c(1,1,2,2,2,3),
item=c("a","b","a","b","c", "b")
)
a_df3
trans4 <- as(split(a_df3[,"item"], a_df3[,"TID"]), "transactions")
trans4
inspect(trans4)
## Note: This is very slow for large datasets. It is much faster to
## read transactions using read.transactions() with format = "single".
## This can be done using an anonymous file.
write.table(a_df3, file = tmp <- file(), row.names = FALSE)
trans4 <- read.transactions(tmp, format = "single",
header = TRUE, cols = c("TID", "item"))
close(tmp)
inspect(trans4)
【讨论】:
以上是关于如何读取 R feom 数据框中的事务?的主要内容,如果未能解决你的问题,请参考以下文章