I am a new R-user and I have a kind of algorithm problem. I made some research on the web and on Stackoverflow, but can’t find my answer.
I have a squared matrix, for example :
A B C D
A 0 0 0 1
B 0 1 1 0
C 1 0 0 0
D 0 1 1 1
This matrix represents links between keywords (A, B, C and D here). A ‘1’ (or a TRUE) means keywords are in relation. For example, the ‘1’ on the first row means A is linked to D.
I need to find the two most linked keywords on the matrix. I know I need to compute the scalar product between each row and the initial matrix. Then I take the sum of the rows and get the maximum.
But, what is the R program which put in a new matrix the product between each row of my matrix, and the matrix itself ?
Thanks!
I thought I had a cleverer answer but it turns out to be slower …
Previous solution:
Test this on something reasonably large:
You will presumably do even better if you can do it in terms of sparse matrices.