I have a text file like the following:
transactionID item
T100 l1,l2,l3
T200 l2,l4
T300 l2,l3
T400 l1,l2,l3
T500 l1,l3
T600 l2,l3
T700 l1,l3
T800 l1,l2,l3,l5
T900 l1,l2,l3
And I would like to read it as a transaction file for arules. I used the following:
transacciones <- read.transactions(file = "/home/norhther/Escritorio/trans.txt",
format = "single",
sep = ",",
header = TRUE,
cols = c("transactionID", "item"),
rm.duplicates = TRUE)
However, I get the following error:
Error in read.transactions(file = "/home/norhther/Escritorio/trans.txt", :
'cols' does not match entries in header of file.
Edit
You should change your format to
basketand use a separator ofsep = " "withcols = 1like this:Created on 2022-11-20 with reprex v2.0.2
According to the documentation of the function
read.transactions, you can use the argumentcols:So you can specify your columns by numeric vector like
c(1,2). Here is a reproducible example:Created on 2022-11-19 with reprex v2.0.2