[R] Merge with transposed matrix.
arun
smartpink111 at yahoo.com
Thu Jul 18 16:32:43 CEST 2013
Hi,
m1<- matrix(NA,5,5)
m1[upper.tri(m1)]<-c(2,3,8,4,9,14,5,10,15,20)
One way would be:
m1[lower.tri(m1)]<-t(m1)[lower.tri(t(m1))]
m1
# [,1] [,2] [,3] [,4] [,5]
#[1,] NA 2 3 4 5
#[2,] 2 NA 8 9 10
#[3,] 3 8 NA 14 15
#[4,] 4 9 14 NA 20
#[5,] 5 10 15 20 NA
A.K.
Hello !
I would like to have some simple sintax in order to fill my matrix with its transposed.
That is, as an example I have a correlation matrix like this, and the transposed one:
> matrix
[,1] [,2] [,3] [,4] [,5]
[1,] NA 2 3 4 5
[2,] NA NA 8 9 10
[3,] NA NA NA 14 15
[4,] NA NA NA NA 20
[5,] NA NA NA NA NA
> transposed.matrix<-t(matrix)
[,1] [,2] [,3] [,4] [,5]
[1,] NA NA NA NA NA
[2,] 2 NA NA NA NA
[3,] 3 8 NA NA NA
[4,] 4 9 14 NA NA
[5,] 5 10 15 20 NA
And I would like to have....
[,1] [,2] [,3] [,4] [,5]
[1,] NA 2 3 4 5
[2,] 2 NA 8 9 10
[3,] 3 8 NA 14 15
[4,] 4 9 14 NA 20
[5,] 5 10 15 20 NA
Thank you very much for your help !!
More information about the R-help
mailing list