[R] decompose a correlation matrix
Liaw, Andy
andy_liaw at merck.com
Thu Sep 23 20:48:13 CEST 2004
> From: Duncan Murdoch
>
> On Thu, 23 Sep 2004 13:08:53 -0500, "Mark Strivens"
> <strivens at bcm.tmc.edu> 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.
>
> x[ row(x) < col(x) ]
>
> will give the entries you want.
>
> Duncan Murdoch
Perhaps slightly more transparent:
x[upper.tri(x)]
or
x[lower.tri(x)]
Best,
Andy
More information about the R-help
mailing list