VZ.Close CBOU.Close SBUX.Close T.Close
VZ.Close 1.0000000 0.5804478 0.8872978 0.9480894
CBOU.Close 0.5804478 1.0000000 0.7876277 0.4988890
SBUX.Close 0.8872978 0.7876277 1.0000000 0.8143305
T.Close 0.9480894 0.4988890 0.8143305 1.0000000
So, Let's say I have these correlations between stock prices. I would like to look at the first row and find the pair with the highest correlation. That would be VZ and T. I then want to remove those 2 stocks as options. Then, among the remaining stocks find the pair with the highest correlation. And so on until all stocks are paired. In this example it would obviously be CBOU and SBUX because they are the only 2 left, but I want the code able to accommodate any number of pairs.