display only the top-right half of a correlation matrix?
On Fri, Aug 19, 2011 at 11:50 AM, Liviu Andronic <landronimirc at gmail.com> wrote:
Dear all Is there an easy way to display only one half (top-right or bottom-left) of a correlation matrix?
require(Hmisc) rcorr(as.matrix(mtcars[ , 1:4]))
? ? ? mpg ? cyl ?disp ? ?hp mpg ? 1.00 -0.85 -0.85 -0.78 cyl ?-0.85 ?1.00 ?0.90 ?0.83 disp -0.85 ?0.90 ?1.00 ?0.79 hp ? -0.78 ?0.83 ?0.79 ?1.00
Use as.dist: here's an example.
x = matrix(rnorm(5*100), 100, 5) as.dist(cor(x))
1 2 3 4 2 -2.892981e-06 3 2.873711e-02 1.002969e-02 4 -5.803705e-02 4.022733e-02 -6.154211e-02 5 1.137083e-01 -8.065676e-02 -9.279316e-02 -8.201583e-02