R语言:如何提取矩阵的左上三角与右下三角?
尝试的代码如下:
> n[upper.tri(n)]<-t(n)[upper.tri(n)]
> n1<-n[,5:1]
> n1
[,1] [,2] [,3] [,4] [,5]
[1,] 5 4 3 2 1
[2,] 10 9 8 7 2
[3,] 15 14 13 8 3
[4,] 20 19 14 9 4
[5,] 25 20 15 10 5
> n1[upper.tri(n1)]<-t(n1)[upper.tri(n1)]
> n1[,5:1]
[,1] [,2] [,3] [,4] [,5]
[1,] 25 20 15 10 5
[2,] 20 19 14 9 10
[3,] 15 14 13 14 15
[4,] 10 9 14 19 20
[5,] 5 10 15 20 25
求解答!!!