How to make in R matrix of intersections and unions over categories?
Maybe something like this?
days <- levels(allt$day)
f <- function(x, y) {
xids <- allt$id[allt$day == x]
yids <- allt$id[allt$day == y]
length(intersect(xids, yids)) / length(union(xids, yids))
}
f <- Vectorize(f)
outer(days, days, f)
# [,1] [,2] [,3]
# [1,] 1.0 0.5 0.2
# [2,] 0.5 1.0 0.5
# [3,] 0.2 0.5 1.0
optionally pipe that into set_colnames(days)
and set_rownames(days)