I need to take the data set containing my product codes (i.e. ABC CDE EFG) and create a matrix with that on both axis with the "inside" being a binary flag to signify that yes that combination has occured in my data set. I have found similar solutions using sparse matrices, but the function will not work with my data. Below is an example of what I will need as a final result. IE ABC-ABC is obviously 1 because they are the same product, but CDE-EFG indicates that when product CDE was bought at the same time as product EFG. My question is what is the best way to create a product-affinity matrix to analyze this set of transaction data.
ABC CDE EFG GHI
ABC 1 0 0 0
CDE 0 1 1 0
EFG 1 1 1 0
GHI 0 0 0 1
EDIT: I am aware of the dplyr package and its affinity function. However I cannot seem to get a succesful run with my data. Perhaps I need to change the data type from a dataframe, however I am not sure if that is the issue or not.