I am trying to find the maximum correlation in each column of a data.frame object by using the cor function. Let's say this object looks like
A <- rnorm(100,5,1)
B <- rnorm(100,6,1)
C <- rnorm(100,7,4)
D <- rnorm(100,4,2)
E <- rnorm(100,4,3)
M <- data.frame(A,B,C,D,E)
N <- cor(M)
And the correlation matrix looks like
>N
A B C D E
A 1.000000000 0.02676645 0.000462529 0.026875495 -0.054506842
B 0.026766455 1.00000000 -0.150622473 0.037911600 -0.071794930
C 0.000462529 -0.15062247 1.000000000 0.015170017 0.026090225
D 0.026875495 0.03791160 0.015170017 1.000000000 -0.001968634
E -0.054506842 -0.07179493 0.026090225 -0.001968634 1.000000000
In the case of the first column (A) I'd like R to return to me the value "D" since it's the maximum non-negative, non-"1" value in column A, along with it's associated correlation.
Any ideas?