[R] decompose a correlation matrix

Mark Strivens strivens at bcm.tmc.edu
Thu Sep 23 23:09:49 CEST 2004

Thanks guys for the help, here's the final (grizzly?)

#generate a correlation matrix
cm<-cor(someDataFrame, y = NULL ...)

# get the list of labels (included in the dataframe)

# retrieve the uppper portion of the correlation matrix (as logical values)
idx <- upper.tri(cm)

# combine the logical values with the marker list
	row=row(t(cm))[idx], col=col(t(cm))[idx], value=cm[idx])

gives the format:

label2 & label1	1	2	0.97712
label3 & label1	1	3	0.84587
label4 & label1	1	4	0.92184
label5 & label1	1	5	0.54698

There seemed to be some issues with the row()and col()
commands not thinking the output of cor() was a matrix
so I used t() to force it into a table...

Department of Molecular and Human Genetics,
Baylor College of Medicine,
1 Baylor Plaza,
TX 77030.

713-798-1947 (work)
832-876-7956 (cell)

More information about the R-help mailing list