Skip to contents

Flatten a correlation matrix into a 2D dataframe.

Usage

flat_cor_mat(cormat, pmat)

Arguments

cormat

A correlation matrix

pmat

A p-value matrix

Value

A dataframe with correlation and p-values for each pairwise comparison

Examples

# Dataset generation
data_test <- data.frame(sapply(c(1:10), function(x) rnorm(10)))

# Correlation matrix calculation
cor_test <- cor(data_test)

# Associated p-values
cor_test_p <- ggcorrplot::cor_pmat(data_test)

# Flatten the correlation matrix
flat_cor_mat(cor_test, cor_test_p)
#>     row column         cor          p
#>  1:  X1     X2 -0.30776912 0.38698347
#>  2:  X1     X3  0.12407125 0.73273363
#>  3:  X2     X3  0.09268351 0.79898750
#>  4:  X1     X4  0.40306578 0.24811452
#>  5:  X2     X4  0.08230669 0.82116887
#>  6:  X3     X4  0.29611227 0.40612472
#>  7:  X1     X5  0.20109071 0.57747453
#>  8:  X2     X5  0.29403272 0.40958597
#>  9:  X3     X5 -0.24891194 0.48800490
#> 10:  X4     X5  0.51192168 0.13037293
#> 11:  X1     X6 -0.07372889 0.83959191
#> 12:  X2     X6  0.26012231 0.46794631
#> 13:  X3     X6 -0.58034303 0.07859154
#> 14:  X4     X6 -0.25747885 0.47264305
#> 15:  X5     X6  0.30471430 0.39195658
#> 16:  X1     X7 -0.34991431 0.32159829
#> 17:  X2     X7  0.18963076 0.59978037
#> 18:  X3     X7 -0.16185480 0.65507297
#> 19:  X4     X7 -0.44484948 0.19767383
#> 20:  X5     X7 -0.49202786 0.14858789
#> 21:  X6     X7  0.27652611 0.43927037
#> 22:  X1     X8  0.42411500 0.22188756
#> 23:  X2     X8  0.45870509 0.18239306
#> 24:  X3     X8 -0.12726615 0.72607071
#> 25:  X4     X8  0.33835040 0.33892914
#> 26:  X5     X8  0.37847932 0.28082818
#> 27:  X6     X8  0.18288207 0.61305927
#> 28:  X7     X8 -0.01603016 0.96494304
#> 29:  X1     X9 -0.42779338 0.21747428
#> 30:  X2     X9  0.25918183 0.46961493
#> 31:  X3     X9 -0.28006556 0.43319106
#> 32:  X4     X9 -0.09240099 0.79958976
#> 33:  X5     X9 -0.12113140 0.73887888
#> 34:  X6     X9  0.39706485 0.25589349
#> 35:  X7     X9  0.17595987 0.62678563
#> 36:  X8     X9  0.20573968 0.56851583
#> 37:  X1    X10  0.41937497 0.22764928
#> 38:  X2    X10 -0.21989394 0.54157382
#> 39:  X3    X10 -0.16066687 0.65747406
#> 40:  X4    X10 -0.22872744 0.52502328
#> 41:  X5    X10 -0.25371081 0.47937343
#> 42:  X6    X10 -0.20884482 0.56256187
#> 43:  X7    X10  0.41622758 0.23152148
#> 44:  X8    X10  0.22477513 0.53240274
#> 45:  X9    X10 -0.54431898 0.10379570
#>     row column         cor          p