3

I am am getting the warning message in the title

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

I have read about this warning message but I still don't figure out why I got it.

Here's my code:

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))

I got the warning message after running

tr <- read.transactions("basket.csv",format="single",sep=",",cols=c(3,4),rm.duplicates = TRUE)

Therefore after running

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

I got 0 rules.

lmo
  • 37,904
  • 9
  • 56
  • 69
Mouna Belaid
  • 653
  • 1
  • 6
  • 11
  • This message is coming from your `read.csv` line or in the `read.transactions` line (which is probably a wrapper for read.csv or friend. I'd recommend you start the debugging by looking at the first 5 or so lines of the file where you get that message and make sure that you have the same number of columns as column headers. – lmo Aug 27 '17 at 11:42
  • What did you mean by saying there is a wrapper for read.csv? – Mouna Belaid Aug 28 '17 at 22:07
  • A wrapper is a function that "wraps around" the inner function usually with the intent of making the inner function easier to use for a specific purpose. As a simple example, you can see that `read.csv` itself is actually a wrapper function for `read.table` by typing `read.csv` (without parentheses) into your console and hitting enter. `read.csv` calls `read.table` internally, with arguments set specifically for reading .csv files. – lmo Aug 29 '17 at 11:52

1 Answers1

3

In case you land here while trying to read a file which has differing number of lines. A post in this mailing list explains how to find which lines are faulty. Let's say for example that you expect 6 columns and that you read.table returns the error message "number of items read is not a multiple of the number of columns". You can find out which line is causing the problem by entering:

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

This example is for tab separated files, use a different separator (sep) if you have csv files.

Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110