I have a huge correlation matrix, but here is just an example:
set.seed(1234) corrmat <- matrix(round (rnorm (36, 0, 0.3),2), ncol=6) rownames (corrmat) <- colnames (corrmat) <- c("A", "b1", "b2", "C", "L", "ctt") diag(corrmat) <- NA corrmat[upper.tri (corrmat)] <- NA A b1 b2 CL ctt A NA NA NA NA NA NA b1 0.08 NA NA NA NA NA b2 0.33 -0.17 NA NA NA NA C -0.70 -0.27 -0.03 NA NA NA L 0.13 -0.14 -0.15 -0.13 NA NA ctt 0.15 -0.30 -0.27 0.14 -0.28 NA > melt(corrmat) X1 X2 value 1 AA NA 2 b1 A 0.08 3 b2 A 0.33 4 CA -0.70 5 LA 0.13 6 ctt A 0.15 7 A b1 NA 8 b1 b1 NA 9 b2 b1 -0.17 10 C b1 -0.27 11 L b1 -0.14 12 ctt b1 -0.30 13 A b2 NA 14 b1 b2 NA 15 b2 b2 NA 16 C b2 -0.03 17 L b2 -0.15 18 ctt b2 -0.27 19 AC NA 20 b1 C NA 21 b2 C NA 22 CC NA 23 LC -0.13 24 ctt C 0.14 25 AL NA 26 b1 L NA 27 b2 L NA 28 CL NA 29 LL NA 30 ctt L -0.28 31 A ctt NA 32 b1 ctt NA 33 b2 ctt NA 34 C ctt NA 35 L ctt NA 36 ctt ctt NA
What I'm looking for - these are correlation values ​​between neighboring ones - means that between A-b1, b1-b2, b2-C, CL, L-ctt (in the order in the column). I need to delete other values ​​and NA. This is expected to be:
X1 X2 value 2 b1 A 0.08 9 b2 b1 -0.17 16 C b2 -0.03 23 LC -0.13 30 ctt L -0.28
So they are in order A-b1-b2-CL-ctt .
Is there an easy way to filter it?
source share