I have this dataframe:
structure(list(`Product Name` = c("Apple", "Banana", "Cherry", "Date", "Elderberry", "Fig", "Guava", "Honeydew", "Kiwi", "Lemon"), Benefits_Claim = c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE), Warnings_Claim = c(FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), Instructions_Claim = c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), Features_Claim = c(TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
I want to create a contingency table that shows counts of overlapping values ... I'm not sure if that's the best way to put it, but ideally it should look something like this:
| (blank) | Benefits | Warnings | Instructions | Features |
|---|---|---|---|---|
| Benefits | ||||
| Warnings | ||||
| Instructions | ||||
| Features |
And the cell overlap of warnings and benefits should show the count of fruits that have both a Benefit and Warning value as TRUE, and so on.
I don't have much code to show for this as I don't really understand how to approach -- any advice gratefully received.
You want the matrix crossproduct of your table:
Cleaned up and diagonal set to zero: