How do I get the top pairs of a cosine similarity matrix like below:
southpark_matrix <- structure(c(0, 0.165272735625452, 0.386480286121192, 0.170696960480773,
0.0869562860988618, 0.165272735625452, 0, 0.251690602341816,
0.472701602991984, 0.137486001150133, 0.386480286121192, 0.251690602341816,
0, 0.255849200006255, 0.0972813221214626, 0.170696960480773,
0.472701602991984, 0.255849200006255, 0, 0.156449701347234, 0.0869562860988618,
0.137486001150133, 0.0972813221214626, 0.156449701347234, 0), .Dim = c(5L,
5L), .Dimnames = list(Docs = c("Mr. Garrison_2", "Cartman_3",
"Mr. Garrison_3", "Cartman_4", "Jimbo_5"), Docs = c("Mr. Garrison_2",
"Cartman_3", "Mr. Garrison_3", "Cartman_4", "Jimbo_5")))
southpark_matrix
Docs
Docs Mr. Garrison_2 Cartman_3 Mr. Garrison_3 Cartman_4 Jimbo_5
Mr. Garrison_2 0.00000000 0.1652727 0.38648029 0.1706970 0.08695629
Cartman_3 0.16527274 0.0000000 0.25169060 0.4727016 0.13748600
Mr. Garrison_3 0.38648029 0.2516906 0.00000000 0.2558492 0.09728132
Cartman_4 0.17069696 0.4727016 0.25584920 0.0000000 0.15644970
Jimbo_5 0.08695629 0.1374860 0.09728132 0.1564497 0.00000000
How do I get the top 2 pairs?
In this example, the top 2 pairs would be. In my actual example, I have over 100 columns and rows.
Cartman_3 Cartman_4 0.4727016
Mr. Garrison_2 Mr. Garrison_3 0.38648029