Flatten a correlation matrix into a 2D dataframe.
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.35200610 0.31851364
#> 2: X1 X3 -0.41984362 0.22707587
#> 3: X2 X3 0.19659675 0.58618446
#> 4: X1 X4 0.07140628 0.84459279
#> 5: X2 X4 -0.37206910 0.28972133
#> 6: X3 X4 0.10997781 0.76231229
#> 7: X1 X5 -0.18858790 0.60182553
#> 8: X2 X5 -0.08050319 0.82503611
#> 9: X3 X5 0.11769013 0.74608920
#> 10: X4 X5 0.03462722 0.92434372
#> 11: X1 X6 0.64653072 0.04337734
#> 12: X2 X6 -0.51530309 0.12742146
#> 13: X3 X6 -0.02395939 0.94761891
#> 14: X4 X6 -0.13212779 0.71596364
#> 15: X5 X6 -0.23457311 0.51418604
#> 16: X1 X7 0.37848813 0.28081606
#> 17: X2 X7 0.06805252 0.85182262
#> 18: X3 X7 -0.36237917 0.30344698
#> 19: X4 X7 -0.12441507 0.73201582
#> 20: X5 X7 -0.01070674 0.97658170
#> 21: X6 X7 -0.20782182 0.56452077
#> 22: X1 X8 0.56804667 0.08669288
#> 23: X2 X8 -0.35173094 0.31891851
#> 24: X3 X8 -0.38030169 0.27832725
#> 25: X4 X8 -0.36655818 0.29748594
#> 26: X5 X8 -0.07154508 0.84429378
#> 27: X6 X8 0.55584484 0.09524304
#> 28: X7 X8 -0.03296347 0.92797072
#> 29: X1 X9 0.28341778 0.42746937
#> 30: X2 X9 0.02423398 0.94701929
#> 31: X3 X9 -0.47125120 0.16917805
#> 32: X4 X9 -0.16732365 0.64405606
#> 33: X5 X9 0.09247643 0.79942893
#> 34: X6 X9 0.33937255 0.33737838
#> 35: X7 X9 -0.19383676 0.59155763
#> 36: X8 X9 0.43549186 0.20840191
#> 37: X1 X10 0.12052527 0.74014755
#> 38: X2 X10 -0.31566239 0.37427705
#> 39: X3 X10 -0.59463757 0.06980958
#> 40: X4 X10 0.31711717 0.37195792
#> 41: X5 X10 -0.04652086 0.89845558
#> 42: X6 X10 -0.35571457 0.31308310
#> 43: X7 X10 0.59563812 0.06922006
#> 44: X8 X10 -0.17952589 0.61970119
#> 45: X9 X10 -0.19158741 0.59594999
#> row column cor p