I need to convert an occurrence matrix (in a file, say infile.txt
) to a co-occurrence matrix as below. Is there any inbuilt function in r to do the same. I can do this using C style programming but I am sure there must be some function to perform the same.
This is my occurrence matrix similar to transaction matrix. A 0
represent non occurrence while 1
represent an occurence of an event.
a b c d
0 1 0 1
0 1 1 1
1 0 0 1
1 1 1 0
1 0 0 0
Co-occurrence can be summarized by checking how many times a pair of events occurred together. This can be found by counting any two columns together by counting how many times both column had 1.
a b c d
a 0 1 1 1
b 1 0 2 2
c 1 2 0 1
d 1 2 1 0
Edit: As pointed out by Jiber, a similar question is here: Create a co-occurrence matrix from dummy-coded observations