I am doing market basket analysis,the datasheet consist grocery items,i want to find out how many unique items are there?please help me
Asked
Active
Viewed 305 times
-6
-
1Please show us your data to help you better – Hardik Gupta Jan 05 '17 at 11:12
-
2Welcome to SO. Please hover over the R tag - it asks for a minimal reproducible example. [Here's a guide](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610); also have a look at the R help files (e.g. `help(p="arules")`). After that, edit & improve your question accordingly. A good one usually provides minimal input data, the desired output data, code tries incl required packages - all copy-paste-run'able in a new/clean R session. *Why?* It makes it easier for all to follow and participate. – lukeA Jan 05 '17 at 11:25
1 Answers
0
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

lukeA
- 53,097
- 5
- 97
- 100