Finding unique values in a dataset for market basket analysis in csv file

Consider for example:

# create demo comma-separated file:
library(arules)
data(Groceries)
lst <- as(Groceries, "list")
writeLines(sapply(lst, paste, collapse=","), tf<-tempfile(fileext = ".csv"))
# readLines(tf)[1:3]
# # [1] "citrus fruit,semi-finished bread,margarine,ready soups"
# # [2] "tropical fruit,yogurt,coffee"                          
# # [3] "whole milk" 

# load csv and check number of items
trans <- read.transactions(tf,"basket",sep=",")
trans
# transactions in sparse format with
#  9835 transactions (rows) and
#  169 items (columns)
ncol(trans)
# [1] 169

Leave a Comment