I'm wondering is there any simple r function able to convert binary columns into square matrix with condition?
I have below source dataframe:
structure(list(SHOES = c(0,0,0,0,0,0,0,0,0),
LEATHER = c(0,0,0,0,0,0,0,0,0),
SPORTSWEAR = c(1,1,1,0,0,0,1,0,0),
SHIRTS = c(1,0,1,0,0,0,0,0,0),
SUITS = c(0,0,1,0,0,0,0,0,1)),
.Names = c("SHOES", "LEATHER", "SPORTSWEAR", "SHIRTS", "SUITS"),
class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -9L))
The result i hope to get as below (Condition: Based on source dataframe,if both columns have 1 then count as 1) then aggregate the counts.
Example 1: SPORTSWEAR & SHIRTS had 2 occurrence (both equal to 1), therefore aggregate count as 2, others remain 0.
Example 2: SHIRTS & SUITS had 1 occurrence (both equal to 1), therefore aggregate count as 1, others remain 0.