Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think this is what you want. First, read in the data:</p> <pre><code># Read in data df&lt;-read.table( textConnection(' 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 ') ,sep=',') names(df)&lt;-c('id','food') </code></pre> <p>Now, build the matrix.</p> <pre><code># Create a matrix of 1's and 0's with id on left and food and column. id.by.food&lt;-as.matrix(table(df$id,df$food)) # If someone ordered an item twice, you'll get a '2'. # Convert everything to 1's. id.by.food&lt;-pmin(id.by.food,1) # Get a correlation matrix round(cor(id.by.food),2) Daily Special Fountain Soda French Fries Hamburger Hot Dog Milkshake Onion Rings Daily Special 1.00 -0.32 -0.50 -0.50 -0.12 -0.12 -0.12 Fountain Soda -0.32 1.00 0.63 0.63 0.40 -0.32 -0.32 French Fries -0.50 0.63 1.00 1.00 0.25 0.25 -0.50 Hamburger -0.50 0.63 1.00 1.00 0.25 0.25 -0.50 Hot Dog -0.12 0.40 0.25 0.25 1.00 -0.12 -0.12 Milkshake -0.12 -0.32 0.25 0.25 -0.12 1.00 -0.12 Onion Rings -0.12 -0.32 -0.50 -0.50 -0.12 -0.12 1.00 Pineapple Cheddar Burger -0.19 -0.48 -0.76 -0.76 -0.19 -0.19 0.66 Pineapple Cheddar Burger Daily Special -0.19 Fountain Soda -0.48 French Fries -0.76 Hamburger -0.76 Hot Dog -0.19 Milkshake -0.19 Onion Rings 0.66 Pineapple Cheddar Burger 1.00 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload