title: How to create a crosstab table using two tables in R?
body: <p>I have excel dataset as follows:</p>
  
  <pre><code>Weight Quantity Price
  72       5      460
  73       8      720
  75       20     830
  95       2      490
  91       15     680
  82       14     340
  88       30     250
  89       6      770
  78       27     820
  98       24     940
  99       29     825
  </code></pre>
  
  <p>I want to get a weight vs Quantity pivot table with sum of prices for each category as follows:</p>
  
  <pre><code>        0-10     10-20     20-30
  70-80   1180     830        820
  80-90   770      340        250
  90-100  490      680        1765
  </code></pre>
  
  <p>I had created two tables for the individual categories to get the average and count using <code>dplyr</code> package as follows:</p>
  
  <pre><code>table1 &lt;- group_by(dataset, Weight = cut(Weight, breaks = c(70,80,90,100))
  result1 &lt;- summarise(table1, Count = n(), Avg_Price = mean(Price, na.rm = T))
  table2 &lt;- group_by(dataset, Quantity = cut(Quantity, breaks = c(0,10,20,30))
  result2 &lt;- summarise(table2, Count = n(), Avg_Price = mean(Price, na.rm = T))
  </code></pre>
  
  <p>Now, How do i use table1 and table2 to create a crosstab table as above?</p>