title: Unclass x tabs on data frame
body: <p>I have the following data frame in R</p>
  
  <pre><code>  LOCATION COLOR  STATE
  1 A        green  fresh
  2 A        red    rotten
  3 B        green  fresh
  4 B        green  fresh
  5 C        red    fresh
  6 C        green  rotten
  </code></pre>
  
  <p>The above data frame can be created in R by using the following script</p>
  
  <pre><code>dat &lt;- read.table(text = "LOCATION COLOR STATE
  1 A green fresh
  2 A red rotten
  3 B green fresh
  4 B green fresh
  5 C red fresh
  6 C green rotten",header = TRUE,sep = "",row.names = 1)
  </code></pre>
  
  <p>I am trying to rearrange my data frame to get the following output</p>
  
  <pre><code>  LOCATION COLOR ROTTEN FRESH
  1 A        red    1      0
  2 A        green  0      1
  3 B        red    0      0
  4 B        green  0      2
  5 C        red    0      1
  6 C        greed  1      0
  </code></pre>
  
  <p>I am trying to do this using the following code</p>
  
  <pre><code>dat &lt;- as.data.frame(unclass(xtabs(~ LOCATION  + COLOR + STATE,dat)))
  </code></pre>
  
  <p>which gives me</p>
  
  <pre><code>            green.fresh   red.fresh  green.rotten red.rotten
  1  A            1           0            0          1
  2  B            2           0            0          0
  3  C            0           1            1          0
  </code></pre>
  
  <p>As you can see, I am very close to the desired format but I am not sure how to make my current output match my desired output. Any ideas or hints would be appreciated.</p>