[R] Triangular matrix upper to down
m.marcinmichal
m.marcinmichal at gmail.com
Mon Sep 26 22:50:24 CEST 2011
Mhy,
I think that this solution It doesn't work with odd dimension. Suppose we
have a reference matrix 13x13 (near i present a table format i.e save by
write.table). This matrix name a response2.
"V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9" "V10" "V11" "V12" "V13"
"1" 0 1.4142135623731 1 1.73205080756888 1.4142135623731 1.73205080756888 1
1.73205080756888 1.4142135623731 1 1.73205080756888 1.73205080756888 1
"2" 1.4142135623731 0 1 1 1.4142135623731 1 1.73205080756888 1
1.4142135623731 1.73205080756888 1.73205080756888 1 1.73205080756888
"3" 1 1 0 1.4142135623731 1.73205080756888 1.4142135623731 1.4142135623731
1.4142135623731 1 1.4142135623731 1.4142135623731 1.4142135623731
1.4142135623731
"4" 1.73205080756888 1 1.4142135623731 0 1 0 1.4142135623731 0 1
1.4142135623731 1.4142135623731 0 1.4142135623731
"5" 1.4142135623731 1.4142135623731 1.73205080756888 1 0 1 1 1
1.4142135623731 1 1.73205080756888 1 1
"6" 1.73205080756888 1 1.4142135623731 0 1 0 1.4142135623731 0 1
1.4142135623731 1.4142135623731 0 1.4142135623731
"7" 1 1.73205080756888 1.4142135623731 1.4142135623731 1 1.4142135623731 0
1.4142135623731 1 0 1.4142135623731 1.4142135623731 0
"8" 1.73205080756888 1 1.4142135623731 0 1 0 1.4142135623731 0 1
1.4142135623731 1.4142135623731 0 1.4142135623731
"9" 1.4142135623731 1.4142135623731 1 1 1.4142135623731 1 1 1 0 1 1 1 1
"10" 1 1.73205080756888 1.4142135623731 1.4142135623731 1 1.4142135623731 0
1.4142135623731 1 0 1.4142135623731 1.4142135623731 0
"11" 1.73205080756888 1.73205080756888 1.4142135623731 1.4142135623731
1.73205080756888 1.4142135623731 1.4142135623731 1.4142135623731 1
1.4142135623731 0 1.4142135623731 1.4142135623731
"12" 1.73205080756888 1 1.4142135623731 0 1 0 1.4142135623731 0 1
1.4142135623731 1.4142135623731 0 1.4142135623731
"13" 1 1.73205080756888 1.4142135623731 1.4142135623731 1 1.4142135623731 0
1.4142135623731 1 0 1.4142135623731 1.4142135623731 0
Suppose we have a next triangular upper matrix response1
"V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9" "V10" "V11" "V12" "V13"
"1" NA 1.4142135623731 1 1.73205080756888 1.4142135623731 1.73205080756888 1
1.73205080756888 1.4142135623731 1 1.73205080756888 1.73205080756888 1
"2" NA NA 1 1 1.4142135623731 1 1.73205080756888 1 1.4142135623731
1.73205080756888 1.73205080756888 1 1.73205080756888
"3" NA NA NA 1.4142135623731 1.73205080756888 1.4142135623731
1.4142135623731 1.4142135623731 1 1.4142135623731 1.4142135623731
1.4142135623731 1.4142135623731
"4" NA NA NA NA 1 0 1.4142135623731 0 1 1.4142135623731 1.4142135623731 0
1.4142135623731
"5" NA NA NA NA NA 1 1 1 1.4142135623731 1 1.73205080756888 1 1
"6" NA NA NA NA NA NA 1.4142135623731 0 1 1.4142135623731 1.4142135623731 0
1.4142135623731
"7" NA NA NA NA NA NA NA 1.4142135623731 1 0 1.4142135623731 1.4142135623731
0
"8" NA NA NA NA NA NA NA NA 1 1.4142135623731 1.4142135623731 0
1.4142135623731
"9" NA NA NA NA NA NA NA NA NA 1 1 1 1
"10" NA NA NA NA NA NA NA NA NA NA 1.4142135623731 1.4142135623731 0
"11" NA NA NA NA NA NA NA NA NA NA NA 1.4142135623731 1.4142135623731
"12" NA NA NA NA NA NA NA NA NA NA NA NA 1.4142135623731
"13" NA NA NA NA NA NA NA NA NA NA NA NA NA
Using compare operation response1 == response2 we have obtain a proper
comparison i.e
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,] NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[2,] NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[3,] NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[4,] NA NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[5,] NA NA NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[6,] NA NA NA NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[7,] NA NA NA NA NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE
[8,] NA NA NA NA NA NA NA NA TRUE TRUE TRUE TRUE TRUE
[9,] NA NA NA NA NA NA NA NA NA TRUE TRUE TRUE TRUE
[10,] NA NA NA NA NA NA NA NA NA NA TRUE TRUE TRUE
[11,] NA NA NA NA NA NA NA NA NA NA NA TRUE TRUE
[12,] NA NA NA NA NA NA NA NA NA NA NA NA TRUE
[13,] NA NA NA NA NA NA NA NA NA NA NA NA NA
But when i use this function:
response1[lower.tri(response1)] <- response1[upper.tri(response1)]
I don't receive a finding symmetric matrix. After using this function matrix
response1 look like this:
"V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9" "V10" "V11" "V12" "V13"
"1" NA 1.4142135623731 1 1.73205080756888 1.4142135623731 1.73205080756888 1
1.73205080756888 1.4142135623731 1 1.73205080756888 1.73205080756888 1
"2" 1.4142135623731 NA 1 1 1.4142135623731 1 1.73205080756888 1
1.4142135623731 1.73205080756888 1.73205080756888 1 1.73205080756888
"3" 1 1.4142135623731 NA 1.4142135623731 1.73205080756888 1.4142135623731
1.4142135623731 1.4142135623731 1 1.4142135623731 1.4142135623731
1.4142135623731 1.4142135623731
"4" 1 0 1.4142135623731 NA 1 0 1.4142135623731 0 1 1.4142135623731
1.4142135623731 0 1.4142135623731
"5" 1.73205080756888 1 0 1 NA 1 1 1 1.4142135623731 1 1.73205080756888 1 1
"6" 1 1 1 1 0 NA 1.4142135623731 0 1 1.4142135623731 1.4142135623731 0
1.4142135623731
"7" 1.4142135623731 1.73205080756888 0 1 1.4142135623731 1.4142135623731 NA
1.4142135623731 1 0 1.4142135623731 1.4142135623731 0
"8" 1.4142135623731 1.4142135623731 1.4142135623731 1 1 1.4142135623731
1.4142135623731 NA 1 1.4142135623731 1.4142135623731 0 1.4142135623731
"9" 1.4142135623731 1.4142135623731 1.4142135623731 1.73205080756888
1.73205080756888 1.4142135623731 0 1 NA 1 1 1 1
"10" 1.73205080756888 1 1.4142135623731 1.4142135623731 1.73205080756888 1 1
1.4142135623731 1.4142135623731 NA 1.4142135623731 1.4142135623731 0
"11" 1 1.4142135623731 1 1.4142135623731 1.4142135623731 1.4142135623731 0
1.4142135623731 1.4142135623731 0 NA 1.4142135623731 1.4142135623731
"12" 1.73205080756888 1.73205080756888 1 1 1.4142135623731 1.73205080756888
1.4142135623731 1 1 1.4142135623731 0 NA 1.4142135623731
"13" 1 1 1.4142135623731 1.4142135623731 1.73205080756888 1 0
1.73205080756888 1.4142135623731 1 1.4142135623731 1.4142135623731 NA
And it's not compare to response2 i.e response1 == response2
"V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" "V9" "V10" "V11" "V12" "V13"
"1" NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"2" TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"3" TRUE FALSE NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"4" FALSE FALSE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"5" FALSE FALSE FALSE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"6" FALSE TRUE FALSE FALSE FALSE NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE
"7" FALSE TRUE FALSE FALSE FALSE TRUE NA TRUE TRUE TRUE TRUE TRUE TRUE
"8" FALSE FALSE TRUE FALSE TRUE FALSE TRUE NA TRUE TRUE TRUE TRUE TRUE
"9" TRUE TRUE FALSE FALSE FALSE FALSE FALSE TRUE NA TRUE TRUE TRUE TRUE
"10" FALSE FALSE TRUE TRUE FALSE FALSE FALSE TRUE FALSE NA TRUE TRUE TRUE
"11" FALSE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE NA TRUE TRUE
"12" TRUE FALSE FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE NA TRUE
"13" TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE TRUE NA
Any suggestion?
Best
Marcin
--
View this message in context: http://r.789695.n4.nabble.com/Triangular-matrix-upper-to-down-tp3845107p3845331.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list