1

I can't seem to get this right. I have a matrix A, and it's upper off-diagonal elements in column order

A [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 A[col(A) > row(A)] [1] 5 9 10 13 14 15 

How would I get these elements in row order? In this case: 5 9 13 10 14 15

Thank you

2
  • 3
    t(A)[lower.tri(A)] Commented Dec 7, 2021 at 22:52
  • B <- t(A); B[col(B) < row(B)] seems to work. Commented Dec 7, 2021 at 22:53

1 Answer 1

4
m <- matrix(1:25, 5, 5) [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 t(m)[lower.tri(m)] [1] 6 11 16 21 12 17 22 18 23 24 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.