读取的项目数不是具有 read.transactions 的列数的倍数

number of items read is not a multiple of the number of columns with read.transactions

我收到标题中的警告消息

number of items read is not a multiple of the number of columns

我已经阅读了这条警告消息,但我仍然不明白为什么会收到它。

这是我的代码:

data <- read.csv("C:/Users/mouna/Desktop/Targa Consult/BD.csv", header=TRUE,sep=";") 
write.table(data, file ="basket.csv",sep=";",row.names=FALSE,col.names = TRUE)
tr <- read.transactions("basket.csv",format="single",sep=",",cols=c(3,4),rm.duplicates = TRUE) 
summary(tr) 
library(arules)
rules <- apriori(tr,parameter=list(supp=0.005,conf=0.8))

我在 运行

之后收到警告消息
tr <- read.transactions("basket.csv",format="single",sep=",",cols=c(3,4),rm.duplicates = TRUE)

因此 运行

rules <- apriori(tr,parameter=list(supp=0.005,conf=0.8))

我有 0 条规则。

以防您在尝试读取行数不同的文件时登陆此处。 A post in this mailing list 解释了如何查找哪些线路有故障。例如,假设您期望 6 列并且您 read.table returns 错误消息 "number of items read is not a multiple of the number of columns"。您可以通过输入以下内容找出导致问题的线路:

x <- count.fields("A.txt", sep="\t")
which(x != 6)  # print out the lines that are not correct

此示例适用于制表符分隔文件,如果您有 csv 文件,请使用不同的分隔符 (sep)。