Creating co-occurrence matrix

Using “dat” from either of the answers above, try crossprod and table:

V <- crossprod(table(dat[1:2]))
diag(V) <- 0
V
#      Items
# Items A B C D E F
#     A 0 1 1 1 1 0
#     B 1 0 3 1 1 1
#     C 1 3 0 1 0 1
#     D 1 1 1 0 1 1
#     E 1 1 0 1 0 0
#     F 0 1 1 1 0 0

Leave a Comment