M O R E L
M O R E L

Reputation: 17

Creating a Transaction Vector for Use in Arules (R)

Hi, I'm trying to create a vector like what I have drawn. A single vector that has entries corresponding to a transaction. Each Item Description belongs to a given Bill Number. I'm trying to essentially have a mapping from Bill Number to Item Desc in a one, to one fashion. My end goal is to feed this vector through arules apriori algorithm to recommend items. Thank you so much!

Hi, I'm trying to create a vector like what I have drawn. A single vector that has entries corresponding to a transaction. Each Item Description belongs to a given Bill Number. I'm trying to essentially have a mapping from Bill Number to Item Desc in a one, to one fashion. My end goal is to feed this vector through arules apriori algorithm to recommend items. Thank you so much!

Edit: dput(cafe)

dput(cafe)

cafe %>%
group_by(`Bill Number`) %>%
select(`Bill Number`, `Item Desc`)

Output

 # A tibble: 145,830 x 2
# Groups:   Bill Number [69,982]
   `Bill Number` `Item Desc`             
   <fct>         <fct>                   
 1 G0470115      MINERAL WATER(1000ML)   
 2 G0470115      MONSOON MALABAR (AULAIT)
 3 G0470116      MASALA CHAI CUTTING     
 4 G0470117      MINERAL WATER(1000ML)   
 5 G0470283      MOROCCAN MINT TEA       
 6 G0470283      MINERAL WATER(1000ML)   
 7 G0470118      MASALA CHAI CUTTING     
 8 G0470118      MOROCCAN MINT TEA       
 9 G0470284      CAPPUCCINO              
10 G0470285      MOROCCAN MINT TEA       

Essentially all I'm trying to do is make a list where each entry corresponds to a unique Bill Number and contains all those Item Desc that belong to it.

For example in my code below notice that Bill Number G0470115 corresponds to two different Item Desc. I want to take both of those Item Desc and put them in an entry in a list. So that entry in the list corresponds to that specific Bill Number. And basically I need to repeat this for all Bill Number.

Upvotes: 0

Views: 52

Answers (0)

Related Questions