R - correlation matrix without duplicated values ​​in the edges

My data looks like

## data =
##  A B C a b c
##  0 1 0 1 1 0
##  0 0 1 1 0 0
##  1 1 0 0 1 0
##  0 0 1 0 0 1
##  0 1 0 1 1 0
##  1 0 0 0 1 0

How to compare data for such results:

##      A    B    C
## a   0.7 -0.2 -0.2 
## b   0.3 -0.5  1.0
## c  -0.7  0.4 -1.0

I am inspired by this article and I want to create a similar heat map. But more than that:

enter image description here

It is executed cor(data), and then crop the matrix of the necessary submatrix - the right approach? Or should I run another function, not cor(data)?

+4
source share
1 answer

Since the desired sub-matrix is ​​not a block from the diagonal of the entire matrix, I do not think there is a better shortcut, and you should use

cor(M)[c("a", "b", "c"), c("A", "B", "C")]
#            A          B          C
# a -0.7071068  0.3333333  0.0000000
# b  0.5000000  0.7071068 -1.0000000
# c -0.3162278 -0.4472136  0.6324555

or just cor(M)[4:6, 1:3].

+1
source

Source: https://habr.com/ru/post/1693798/


All Articles