I have a 9 column dataframe consisting of an inventory of factors. Each row can contain all 9 columns (since this row contains 9 "things"), but most of them do not (most of them are between 3-4). The columns are also not specific, as if item 200 is displayed in columns 1 and 3, this is the same. I would like to create a matrix that is binary for each row that includes all factors.
Ex (reduced to 4 columns to get the exact point)
R1 3 4 5 8 R2 4 6 7 NA R3 1 5 NA NA R4 2 6 8 9
Gotta turn into
1 2 3 4 5 6 7 8 9 r1 0 0 1 1 1 0 0 1 0 r2 0 0 0 1 0 1 1 0 0 r3 1 0 0 0 1 0 0 0 0 r4 0 1 0 0 0 1 0 1 1
I looked at writeBin / readBin, K-clustering (this is what I would like to do, but I need to get rid of NA first), fuzzy clustering, tag clustering. Just somehow lost about which direction to go.
I tried writing two loops that extract data from the matrix by column / row and then store 0 and 1 respectively in the new matrix, but I think there were problems with the area.
You guys are the best. Thanks!
user800811
source share