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.
dat <- 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
Intended output: