I am very new to R so I apologize if this question is relatively novice. I have a list of roughly 33,000 rows that shows order ID and products ordered within that order ID. Structured as follows:
Order.ID Product
193505 Pineapple Cheddar Burger
193505 Onion Rings
193564 Pineapple Cheddar Burger
193623 Hamburger
193623 French Fries
193623 Fountain Soda
193623 Hot Dog
193631 Hamburger
193631 French Fries
193631 Milkshake
193644 Daily Special
193726 Hamburger
193726 French Fries
193726 Fountain Soda
193728 Hamburger
193728 French Fries
193728 Fountain Soda
193738 Hamburger
193738 French Fries
193762 Hamburger
193762 French Fries
193762 Fountain Soda
193762 Hamburger
193762 French Fries
193762 Fountain Soda
I would like to generate a correlation matrix that reflects the correlation of each item being ordered in the same order ID as each other item. I started by using a table(ID, Product)
which gave me products ordered within each order. Now I am stuck on how to go about counting the number of orders of each other product (product 2-k) given product 1 has been ordered. Ideally I would like to run that analysis for every product and turn that into a matrix but evaluating one properly seemed like the logical first step.
I would appreciate any guidance I can get on this problem. Thanks in advance.