我的CSV文本数据类似于:
citrus fruit,semi-finished bread,margarine,ready soups
tropical fruit,yogurt,coffee
whole milk
pip fruit,yogurt,cream cheese ,meat spreads
other vegetables,whole milk,condensed milk,long life bakery product
whole milk,butter,yogurt,rice,abrasive cleaner
我想将其加载到稀疏事务表单中,这样做的最佳方法是什么? 我希望能够在其上使用arules包
答案 0 :(得分:1)
您可以使用readLines
,然后使用strsplit
,然后强制使用arules'transactions
对象
tran <- readLines("transactions.csv") # read all lines
tran <- strsplit(tran, ",", fixed=TRUE) # split each line by commas, returns a list
library(arules)
tran <- as(tran, Class = "transactions") # coerce to transaction object
rules <- apriori(tran, parameter=list(support=0.1)) # etc
inspect(rules[1])