0

我有 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 包

4

1 回答 1

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])
于 2015-01-16T00:24:15.817 回答