0

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.

M O R E L
  • 17
  • 4
  • 1
    Your data (structure) and problem description is not clear to me. Please include sample data in a reproducible "copy & paste"-able format (using e.g. `dput`); don't include data as a screenshot as we cannot (easily) extract data from an image. I recommend showing minimal & representative sample data and your corresponding expected output along with what you're trying to do. That will give us something to work with. – Maurits Evers Jul 10 '22 at 23:30
  • Thank you Maurits, is what I posted sufficient now? – M O R E L Jul 12 '22 at 14:55
  • Likely duplicate: [Collapse / concatenate / aggregate a column to a single comma separated string within each group](https://stackoverflow.com/questions/15933958/collapse-concatenate-aggregate-a-column-to-a-single-comma-separated-string-w) – Ian Campbell Jul 12 '22 at 14:59

0 Answers0