# Re: [R] cross-correlation table with subscript or superscript to indicate significant differences

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 05 May 2011 12:17:25 -0400

```>
> Hi, I wonder whether the following is possible with R, and whether
> anyone has done that and can share his/her code with me. I have a
> correlation matrix, and I want to create a correlation table that I
> can copy to Microsoft Word with a superscript above each
> correlation, indicating significant differences in the same row.
> That is, when correlations in the same row do not share superscript,
> it means that they are significantly different from each other.
> thanks,yoav
> 	[[alternative HTML version deleted]]

```

An example with data and the desired result might help focus the discussion.

This shows how to set up an example showing how extract the row numbers from a correlation matrix with absolute values above 0.5 but less than 1 (to exclude the trivial cases).

``` > set.seed(123)
> X <- matrix(rnorm(100), 10)
> apply(cor(X), 2, function(x) which(abs(x) > 0.5 & x < 1)  )
```

[]
 2 4 8

[]
 1 3

[]
 2 6 9

[]
 1 7

[]

integer(0)

[]
 3 10

[]
 4

[]
 1

[]
 3

[]
 6

This would extract the rownames if they are letters[1:10]

> lapply( apply(cor(X), 2, function(x) which(abs(x) > 0.5 & x < 1) ), function(x) rownames(X)[x])
[]
 "b" "d" "h"

[]
 "a" "c"

[]
 "b" "f" "i"

[]
 "a" "g"

[]

character(0)

[]
 "c" "j"

[]
 "d"

[]
 "a"

[]
 "c"

[]
 "f"

Exactly how we are supposed to pass this to MS Word does not seem to be a proper question for this mailing list.

```--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help