How to create a cross reference table in R?
<p>I am trying to make a cross reference table from a dataset in long format with IDs that have registered preferences of flower species. The cross reference table should list all the flower vertically and horizontally and for each flower show the frequency of likes of other flowers based upon the dataset.</p>

<pre><code>dat &lt;- data.frame(
  ID=rep(1:5, c(3,3,2,1,4)),
  Flower=c("Azalea","Begonia","Buttercup","Rose","Sunflower")[
    c(4,2,5,2,1,3,4,3,1,5,4,3,2)
  ]
)

#   ID    Flower
#1   1      Rose
#2   1   Begonia
#3   1 Sunflower
#4   2   Begonia
#5   2    Azalea
#6   2 Buttercup
#7   3      Rose
#8   3 Buttercup
#9   4    Azalea
#10  5 Sunflower
#11  5      Rose
#12  5 Buttercup
#13  5   Begonia
</code></pre>

<p>Intended output:</p>

<p><a href="https://i.stack.imgur.com/RvBBF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RvBBF.png" alt="enter image description here"></a></p>