I want to copy the upper triangle to the lower triangle of a bunch of matrices stored in a list.
Create a list of matrices with only the upper triangle filled with data:
m1<-matrix(1:9, 3, 3);lower.tri(m1);m1[lower.tri(m1)]<- NA; m1 m2<-matrix(9:18, 3, 3);lower.tri(m2);m2[lower.tri(m2)]<- NA; m2 m3<-matrix(18:27, 3, 3);lower.tri(m3);m3[lower.tri(m3)]<- NA; m3 m4<-matrix(27:36, 3, 3);lower.tri(m4);m4[lower.tri(m4)]<- NA; m4 L<-list(m1,m2, m3, m4); L
To copy the upper triangle to the lower triangle of the matrix, you can use:
M <- m1 for(i in 1:nrow(M)) {for(j in 1:i) {M[i,j]=M[j,i] }} M
However, I want to copy the top triangle to the bottom for each of the matrices in the list βLβ
list matrix r
Rockdrigo
source share