[R] decompose a correlation matrix
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Thu Sep 23 21:37:36 CEST 2004
On 23-Sep-04 Mark Strivens wrote:
> Is there a simple way to decompose the upper triangle
> of a correlation matrix to a linear list;
>
> For example:
>
> X Y Z
> X 1 2 3
> Y 2 1 4
> Z 3 4 1
>
> so you get a list like:
>
> xy 2
> XZ 3
> YZ 4
>
> I suspect you can do it with a matrix transformation, but
> that beyond me at present.
Let C be your correlation matrix. Then:
C[lower.tri(C)]
or equivalently
C[upper.tri(C)]
E.g. (in your notation):
> C
[,1] [,2] [,3] [,4]
[1,] 1 2 3 4
[2,] 2 1 5 6
[3,] 3 5 1 7
[4,] 4 6 7 1
> (C[lower.tri(C)])
[1] 2 3 4 5 6 7
See ?lower.tri
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861 [NB: New number!]
Date: 23-Sep-04 Time: 20:37:36
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list